Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#10472 closed bug (invalid)

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:
Blocked by: Blocking:

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 (4)

comment:1 Changed 8 years ago by dmethvin

Resolution: invalid
Status: newclosed

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 7 years ago by matteopuppis@…

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

comment:3 Changed 7 years ago by anonymous

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

comment:4 Changed 7 years ago by anonymous

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

Note: See TracTickets for help on using tickets.