Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Manipulating select options with JavaScript

    Hello Coders,

    I have been working with this script all day, but it still won't work. Any ideas? It is supposed to modify the options in a select based on the value of the previous select.

    Here is the Script:
    [CODE]
    <script>

    var option = getElementbyId.("select");
    if (option.value == "Axiom OA"){
    document.write("<option>Magnesium</option>");
    document.write("<option>Aluminum</option>");}
    else {document.write("<option>TryAgain!</option>");}
    </script>
    [CODE]

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,286
    Thanks
    12
    Thanked 343 Times in 339 Posts
    lots of typos in there. the error console should have a bunch of complaints.

    and of course the usual, document.write() will kill you if used after the page loaded.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    This close?
    Code:
    <html>
    <head>
    <title></title>
    
    </head>
    <body>
    <div>Data Recovery Required?:<br />
    <select name="data" id="DataRec" onchange="examp(this.value);">
    	<option>Please Select</option>
    	<option value="Yes">Yes</option>
    	<option value="No">No</option>
    	<option value="Axiom OA">Axiom OA</option>
    </select>
    <div id="next"></div>
    </div>
    
    <script type="text/javascript">
    function examp(stuff){
    	if (stuff == "Axiom OA"){
    		document.getElementById("next").innerHTML ="<select><option>Magnesium</option><option>Aluminum</option></select>";
    	}else {
    		document.getElementById("next").innerHTML ="TryAgain!";
    	}
    }
    </script>
    </body>
    </html>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,286
    Thanks
    12
    Thanked 343 Times in 339 Posts
    does it work?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Tags for this Thread

    Posting Permissions

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