PDA

View Full Version : inserting a <select> field into a js calculator in place of an input??



joelnativeenergy
04-30-2007, 04:05 PM
Hey guys,

I'm trying to insert a drop down menu into an html form, and code for my js calculator and so far not working..

The calc works just fine with all <input> fields however I need to add a <select> drop down with numarical values for each state upone selected to be added in the calculation. I have left the code for "inputs.state.value" in the string untouched as if "state" was still a field and not a selectable drop down.

Any idea how I can get this to work?

(with drop down)
http://www.nativeenergy.com/Splash/event/event2.html

(with input field "Venue1" instead of "state")
http://www.nativeenergy.com/Splash/event/event.html

Thank very much guys.. I'm an in house desiger so I have no inside help LOL.

Cheers,
Joel

boogyman
04-30-2007, 04:27 PM
document.FORMNAME.SELECTNAME.value

and this example in your form



<form name="FORMNAME">
State <select name="SELECTNAME"> <option value="alabama">Alabama</option> ....</select>
</form>


obviously its not the same as you have but if you have any problems translating let me know.. dont worry about putting a name for each<option> as whatever you have for the SELECTNAME with carry the value of then option selected

joelnativeenergy
04-30-2007, 04:47 PM
Some further explination might be needed :P here is what I have in the code:

for the js:

var waste = inputs.people.value * 5/2000 *0.30 * (44/12);
var lodging = (inputs.hotel.value * 40 * 1.44 + inputs.hotel.value * 155.3 * 0.1206)/2000;
var state = ((inputs.state.value * inputs.days.value * 0.031 * 1.44)+(inputs.state.value * inputs.days.value * 0.093 * 0.1206))/2000;
var venue2 = ((inputs.Venue2.value * inputs.days.value * 0.031 * 1.44)+(inputs.Venue2.value * inputs.days.value * 0.093 * 0.1206))/2000;
var driving = ((inputs.Car_amount.value * inputs.Car_miles.value)/22.38 * 19.56)/2000;
var flying = ((inputs.Air_amount.value * inputs.Air_miles.value) * 0.89)/2000;

total_tons = Math.ceil(waste + lodging + state + venue2 + driving + flying);
inputs.tot.value = addCommas(total_tons);

And what I have for the state dropdown (shortened)

<select name="state" size="1">
<option value="100">Alabama</option>
<option value="120">Alaska</option>
<option value="120">Arizona</option>
</select>


How can I add this <select> to the above js calculation string to accept the given value of a dropdown item selected and add to the calculation as if it was an <input> field (which works perfectly)

Just lost here.. thank you for the help.

joelnativeenergy
04-30-2007, 08:50 PM
If you would like an update.. I have tried a couple things with no sucess:

http://www.nativeenergy.com/Splash/event/event4.html

boogyman
04-30-2007, 08:56 PM
change

inputs.state.value
to


document.state.value


untested, but should work