taxmanrick Posted October 13, 2008 Share Posted October 13, 2008 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 More sharing options...
jeffman Posted October 13, 2008 Share Posted October 13, 2008 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 More sharing options...
taxmanrick Posted October 13, 2008 Author Share Posted October 13, 2008 Thanks fro the help and advice. I will try it. Link to comment Share on other sites More sharing options...
taxmanrick Posted October 13, 2008 Author Share Posted October 13, 2008 That is a lot of code to do something I thought was so simple. I think I understand what is going butI'm not sure what this line does except maybe define a blank variable????var digits = document.getElementById("digits"); Link to comment Share on other sites More sharing options...
justsomeguy Posted October 13, 2008 Share Posted October 13, 2008 That line gets a reference to an element called digits, which is your text field. Using that reference you can get or set the field's value, size, formatting, etc. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.