option.selected can't be changed

Discussion in 'HTML' started by M.C, Jul 16, 2005.

  1. M.C

    M.C Guest

    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!
     
    M.C, Jul 16, 2005
    #1
    1. Advertising

  2. M.C

    Adrienne Guest

    Gazing into my crystal ball I observed "M.C" <> writing
    in news::

    > 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".

    >
    ><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
     
    Adrienne, Jul 16, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    716
    Rosanne
    Oct 11, 2005
  2. John
    Replies:
    5
    Views:
    1,017
    dorayme
    Mar 1, 2010
  3. mldardy
    Replies:
    0
    Views:
    982
    mldardy
    Sep 28, 2010
  4. Mark Kolber
    Replies:
    4
    Views:
    353
  5. mxbrunet
    Replies:
    1
    Views:
    228
Loading...

Share This Page