Results 1 to 3 of 3

Thread: HTML DOM problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    For some reason, I can't extract the value out of a drop down list.

    When the user clicks a text text box, I want an alert to come up with the value of the selection list.

    In the following page, the alert box always comes up empty.

    Code:
    <html>
    <head>
    <SCRIPT LANGUAGE=javascript>
    <!--
    
    function foo(){
    
    ind = document.myform1.cost.options.selectedIndex
    val = document.myform1.cost.options[ind].value
    alert(val)
    
    'also tried alert(document.myform1.cost.value) -- doesn't work
    
    
    document.myform1.cost.focus()
    
    }
    -->
    
    </SCRIPT>
    </head>
    
    <form name="myform1" action="run.asp" method="POST">
    	<select name="cost">
    		<option>60</option>
    		<option>70</option>
    		<option>80</option>
    		<option>90</option>
    		<option>100</option>
    	</select>
    	<input type="text" name="text1" onfocus="foo();">
    </form>
    </html>

    Why doesnt this work?!!

    tx
    dvst8
    Secret to long life:
    Keep breathing as long as possible.

  2. #2
    Junior Member
    Join Date
    May 2000
    Posts
    28

    simple

    Your JavaScript is fine, what you need to do is set the value attribute in you option tag:

    Code:
    <form name="myform1" action="run.asp" method="POST">
    	<select name="cost">
    		<option value="60">60</option>
    		<option value="70">70</option>
    		<option value="80">80</option>
    		<option value="90">90</option>
    		<option value="100">100</option>
    	</select>
    	<input type="text" name="text1" onfocus="foo();">
    </form>

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142

    doh!

    thanks!

    i wasted a lot of time trying to figure out what was wrong!!

    dvst8
    Secret to long life:
    Keep breathing as long as possible.

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