Jump to content

Returning the value of a dropdown list in a text box


taxmanrick

Recommended Posts

I am trying to create a calculator that will estimate taxes. The user will select from a dropdown list of 'wards' and the value will be stored and used later. The problem is, I can't be sure that it is storing it because I can't even display the value in a text box. Here is the code so far:

<HTML><HEAD><TITLE>Tax Extimator </TITLE></HEAD><BODY><CENTER><H1>Tax Calculator</H1></CENTER>Select the Ward<FORM name = "wardForm">  <SELECT name = "wardChoice" id = "wardChoice" onChange = "tax_calc()">	<OPTION VALUE=1>Ward 1 A</option>	<OPTION VALUE=2>Ward 1 R</option>	<OPTION VALUE=25>Ward 1 W</option>	<OPTION VALUE=23>Ward 2 A</option>	  </SELECT></FORM><script Language="JavaScript"><!--function tax_calc(wardForm) { var selection;  selection = document.getElementById("wardChoice.value"); document.ward.digits.value = selection; }//--></SCRIPT><form name="ward" size = "6"><input type ="text" name ="digits" id ="digits" value ="0.08138" /></form></BODY></HTML>

Link to comment
Share on other sites

We'd all be happy campers if the value of the selected option were in fact stored in select.value. But it's not. I wrote this out the long way so you can see exactly what's going on. Usually I take a few shortcuts.

function tax_calc () {   var selection = document.getElementById("wardChoice");   var option_number = selection.selectedIndex;   var option_value = selection.options[option_number].value;   var digits = document.getElementById("digits");   digits.value = option_value;}

Extra tip: stop capitalizing your tags and tag attributes.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...