Bug Tracker

Modify

Ticket #1851 (closed bug: worksforme)

Opened 6 years ago

Last modified 5 years ago

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

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>

Change History

comment:1 Changed 5 years ago by davidserduke

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

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:

$(document).ready(function () {
  foo();
});

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.

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.