Results 1 to 2 of 2

Thread: troubleshoot this code?

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Red face troubleshoot this code?


    I don't know what I'm doing wrong here can anyone take a look?


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/stict.dtd">

    <html>
    <head>

    <title>first form example2</title>



    <script type="text/javascript">



    function displayvalue(){
    var selected = document.forms["starform"].startype.value;

    alert("You selected " + selected);
    }


    </script></head>
    <body>

    <form id="starform" action ="" onsubmit="return false;">

    Select a constellation:

    <select onchange="displayvalue() name="startype">

    <option selected="selected"></option>

    <option value= "a">a</option>
    <option value= "b">b</option>
    <option value= "c">c</option>

    </select>
    </form>

    </body>
    </html>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here, this should work:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/stict.dtd">
    
    <html>
    <head>
      <title>first form example2</title>
      <script type="text/javascript">
        function displayvalue(me){
          alert("You selected "+me.value);
        }  
      </script>
    </head>
    <body>
      <form id="starform" onsubmit="return false;">
    Select a constellation: 
        <select onchange="displayvalue(this);" name="startype">
          <option selected="selected"></option>
          <option value="a">a</option>
          <option value="b">b</option>
          <option value="c">c</option>
        </select>
      </form>
    </body>
    </html>
    Although I completely changed you're javascript to more effecient like js, you can just change this line (in your script):
    Code:
    <select onchange="displayvalue() name="startype">
    To this:
    Code:
    <select onchange="displayvalue()" name="startype">
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    evan (05-07-2009)

Bookmarks

Posting Permissions

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