Results 1 to 2 of 2

Thread: Problems with selectbox & Jscript

  1. #1

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Problems with selectbox & Jscript

    Hi all I'm not much cop at JavaScript ( thought i do thinlk it's pretty cool) now how can i display the value of an item the code bellow sort of works

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- 
    
    function submitform_List() {
    
    alert("TEST!!!");
    document.choiceForm.MyAccount.length++;
    alert(document.choiceForm.MyAccount.length);
    alert(document.choiceForm.MyAccount[0].text);
    
    document.choiceForm.MyAccount[1].text="BombDrop";
    
    //I can not display the value i have added to the new option???
    document.choiceForm.MyAccount[1].value="123";
    alert(document.choiceForm.MyAccount.value);
    
    
    //document.choiceForm.submit();
    }
    </script>
    Any help would be great

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Just incrementing the length doesn't add an actual item!
    Code:
    <script type="text/javascript">
    function submitform_list() {
      var form = document.getElementById("choiceForm");
      var select = form.elements["MyAccount"];
      var option = document.createElement("option");
      option.text = "BombDrop";
      option.value = "123";
      select.appendChild(option);
      // Now there's a real new option there.
      alert(select.options[select.options.length-1].value);
    }
    </script>
    http://www.quirksmode.org/
    contains a lot of resources on proper JavaScript.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width