HighDots Forums  

option.selected can't be changed

alt.html alt.html


Discuss option.selected can't be changed in the alt.html forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
M.C
 
Posts: n/a

Default option.selected can't be changed - 07-16-2005 , 06:43 AM






I encoutered a problem which almost drove me crazy, but let me skip my
personal problem, and show you this really strange problem.
msdn.microsoft.com told me that selected is a boolean attribute
with "false" as its default value.However, unfortunately, I found that
not only "selected" was "true" when I assigned "false" to it, but also
remained "true" all the time even when I tried to change it to "false".
here go the codes:
<body>
<form >
<select >
<option id="op" value="initialValue" selected="false">op</option>
<select>
</form>

<script>
function fun(){
op.value="modifiedValue";
var bool=(1==2);
op.selected=bool;
alert("op.selected is "+op.selected + " op.value is "+op.value);
}
fun();
</script>
</body>

I have tried to find some explanation by google but without any
result, I appriciate it if you tell me why or where i am wrong.
thank you!


Reply With Quote
  #2  
Old   
Adrienne
 
Posts: n/a

Default Re: option.selected can't be changed - 07-16-2005 , 05:31 PM






Gazing into my crystal ball I observed "M.C" <MaXiaochi (AT) gmail (DOT) com> writing
in news:1121510598.031857.194210 (AT) o13g2000cwo (DOT) googlegroups.com:

Quote:
I encoutered a problem which almost drove me crazy, but let me skip my
personal problem, and show you this really strange problem.
msdn.microsoft.com told me that selected is a boolean attribute
with "false" as its default value.However, unfortunately, I found that
not only "selected" was "true" when I assigned "false" to it, but also
remained "true" all the time even when I tried to change it to "false".
here go the codes:
body
form
select
option id="op" value="initialValue" selected="false">op</option
select> </form
Here's your problem
<option id="op" value="initialValue" selected>op</option>

If you are using XHTML where all attributes must have values, then you
would use selected="selected".

For checkboxes, it's checked, or checked="checked".

Quote:
script
function fun(){
op.value="modifiedValue";
var bool=(1==2);
op.selected=bool;
alert("op.selected is "+op.selected + " op.value is "+op.value);
}
fun();
/script
/body

Now try running your script.

--
Adrienne Boswell
http://www.cavalcade-of-coding.info
Please respond to the group so others can share


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.