My javascript is suppose to add value to a price variable and then return the price, my trouble is that i am using a select option and when i have more than one the price will only use the id of the last if statement, here is my HTML;
<form>
<select>
<option name ="Bristol "value="40.0" id ="BN1">Bristol - Newcastle</option>
<option name ="London "value="35.0" id ="BL1">Bristol - London</option>
</select>
<button type="button" onclick="BookingFare(); return false;">Submit</button><br>
</form>
<label id='priceBox'></label>
and here is my Javascript
function BookingFare() {
var price = 0;
//var ofAdults = getElementById('adults').value;
//var ofChildren = getElementById('children').value;
var BN1 = document.getElementById('BN1').value;
var BL1 = document.getElementById('BL1').value;
if (BL1) {
var price = BL1;
}
if (BN1) {
var price = BN1;
}
document.getElementById('priceBox').innerHTML = price;
}
So basically the program will return the price of BN1, even if i choose Bristol - London. Any suggestions appreciated.