0

I have a function that based on a checkbox id determines a price value. This works fine except I need to change the checkbox to a select. I tried to change the line:

if(peo14.checked==true)

To this:

if(peo14.select==Yes)

This did not work...how do I alter this to a Yes/No select?

function peoPrice()
{
    var peoPrice=0;
    //Get a reference to the form id="quicksheet"
    var theForm = document.forms["quicksheet"];
    //Get a reference to the checkbox id
    var peo14 = theForm.elements["peo14"];  

    //If they checked the box set peoPrice to value
    if(peo14.checked==true)
    {
        peoPrice=199;
    }       
    //finally we return the peoPrice
    return peoPrice;
}
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79
  • http://stackoverflow.com/questions/1085801/how-to-get-the-selected-value-of-dropdownlist-using-javascript – Andy Sep 10 '13 at 17:04

2 Answers2

0

You have to use the .options property and choose the selected index, then get the value of that index.

if (peo14.options[ peo14.selectedIndex ].value === 'Yes') {
    peoPrice = 199;
}
Joe Simmons
  • 1,828
  • 2
  • 12
  • 9
-1

Select Box


<select id="peo14" name='peo14' >
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
function peoPrice()
{
    var peoPrice=0;
    var e = document.getElementById("peo14");
    var peo14val = e.options[e.selectedIndex].value;

    if(peo14val=="Yes")
    {
        peoPrice=199;
    }       
    //finally we return the peoPrice
    return peoPrice;
}


sushil bharwani
  • 29,685
  • 30
  • 94
  • 128