Opened 15 years ago
Closed 15 years ago
#1851 closed bug (worksforme)
jQuery stops javascript to update selected = true in Safari
Reported by: | angelochen960 | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.2.1 |
Component: | core | Version: | 1.2.1 |
Keywords: | safari select | Cc: | |
Blocked by: | Blocking: |
Description
I try to set a selected option in a Select box, the following code works without jQuery function defined, once I un-comment the jQuery part, it works in Firefox, but not in Safari any more.
<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 TransitionalEN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.2.1.js"></script> <script type="text/javascript">
/* un commenting this will cause safari to fail
$(document).ready(function(){ })
*/
function foo() {
var s = document.getElementById( "02" ); s.selected = true; s.defaultSelected = true;
};
</script> </head>
<body onload="foo();"> <form id="form1" name="form1" method="post" action="">
<select name="state" id="state">
<option id="01" value="NY">New York</option> <option id="02" value="AL">Alaska</option> <option id="03" value="KY">Kentuky</option> <option id="04" value="IA">IOWA</option>
</select>
</form> </body> </html>
I suggest if you are using jQuery to take out the onload attribute from body and put the foo function call in the document ready function like:
It is possible there may be problems with some browser versions when using body onload and the document ready functionality.
That said, I was unable to reproduce this bug in Safari 3 Win. So if this really is a problem and there is a specific version that failed please reopen the bug with that information.