Bug Tracker

Modify

Ticket #10472 (closed bug: invalid)

Opened 20 months ago

Last modified 3 months ago

jquery-1.6.2 not changing select (default) element in Firefox when default is first

Reported by: barnaby.norman@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.6.4
Keywords: Cc:
Blocking: Blocked by:

Description

Attempting to change the value of select drop-down fails without error on Firefox 7.0.1 when the option changing from is the first option in the list.

I tested this on Chrome and Safari and found it to work as expected.

The script used is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
	<head>
		<title>test</title>
		<script src="js/jquery-ui-1.8.16.custom/js/jquery-1.6.2.min.js" type="text/javascript"></script>
	</head>
	<body>

		<div class="chrtTimeSelect">
			<select id="chrt_time">
				<option value="1" selected="selected">24 hours</option>
				<option value="2">6 months</option>
				<option value="3">1 year</option>
				<option value="4">5 years</option>
				<option value="5">10 years</option>
				<option value="6">20 years</option>
			</select>
		</div>

		<script>


			$(document).ready(function(){

				var time_selection = "5";

				$("#chrt_time option[selected]").removeAttr("selected");
				$("#chrt_time option[value=" + time_selection + "]").attr("selected", "selected");

			});

		</script>
	</body>
</html>

Change History

comment:1 Changed 20 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

Attributes aren't dynamic. Use .val() on the select or .prop() on the option element you want to select:

 http://jsfiddle.net/dmethvin/KvdKE/

comment:2 Changed 10 months ago by matteopuppis@…

It didn't work even if i use .val()...

comment:3 Changed 3 months ago by anonymous

I have the same problem... Someone found any solution?

comment:4 Changed 3 months ago by anonymous

Solution founded! Use ".removeAttr("selected").removeAttr("selected")".

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.