you are correct, this works in Safari, IE, Opera and Firefox,
interestingly Firefox failed on this:
<option id="01" value="NY" selected="selected">New York</option>
when the options are ajax loaded into the element, thanks for your
help, also to all others who responded to me, a difficult part of
Javascript programming is, finding a way to make it work with all
major browsers.


On Oct 28, 2:33 am, "Lee Hinde" <[EMAIL PROTECTED]> wrote:
> Just for the archives, I found that Safari won't let jQuery add a
> selected attribute, but if one exists jQuery can toggle it.
>
> E.g.,      <option id="01" value="NY" selected="">New York</option>
>
> should work.
>
> I sorted through this a few months ago, so my memory may be a bit off.
>
> On 10/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > 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, please help,
> > Thanks.
>
> > A.C.
>
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "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>

Reply via email to