Results 1 to 5 of 5

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

  1. #1
    Join Date
    Nov 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default inserting a <select> field into a js calculator in place of an input??

    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

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Code:
    document.FORMNAME.SELECTNAME.value
    and this example in your form

    HTML Code:
    <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

  3. #3
    Join Date
    Nov 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Nov 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If you would like an update.. I have tried a couple things with no sucess:

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

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    change
    Code:
    inputs.state.value
    to
    Code:
    document.state.value
    untested, but should work

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
  •