strange behavior when changing select's value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TDN

    strange behavior when changing select's value

    Hi,

    I expect to see "foo" for the 2nd alert. Instead, the value of select is
    cleared. Am I missing something? Thanks for your help.

    <html>
    <head><title>Fo o</title>
    <script language="javas cript">
    <!--
    function foo()
    {
    alert('Before change: ' + document.contro l.titleFont.val ue);
    document.contro l.titleFont.val ue = 'foo';
    alert('After change: ' + document.contro l.titleFont.val ue);
    }
    -->
    </script>
    </head>
    <body>
    <form name="control" method="POST">
    <select name="titleFont ">
    <option value="sans-serif">Arial</option>
    <option value="serif">T imes</option>
    </select>&nbsp;
    <input type="submit" name="control" value="Submit" onclick="return
    foo()"/>
    </form>
    </body>
    </html>



  • TDN

    #2
    Re: strange behavior when changing select's value

    [snipped]

    Well, I found out that I need to change the value of the selected index.
    Interesting indeed! Here goes:

    .....
    var index = document.contro l.titleFont.sel ectedIndex;
    document.contro l.titleFont[index].value = 'foo';
    alert(document. control.titleFo nt.value);
    .....

    Thanks


    Comment

    Working...