I have created 4 drop down lists each drop down list has false values and one true value. (See the code below for the lists).
My plan is to cause a message to appear and a new page to appear based on all the values being true.
<input name="button" type="submit" class="main" id="button" value="Submit" #nclick="checkValues();"/>.
//This is the button and where I have tried to assign the check values function
<select name="select_box" size="1" class="main" id="select_box">
<option value="true">50p</option>
<option value="false">1p</option>
<option value="false" selected="selected">20p</option>
<option value="false">£2</option>
</select>
<select name="select_box4" size="1" class="main" id="select_box4">
<option value="true">£2</option>
<option value="false">1p</option>
<option value="false">20p</option>
<option value="false" selected="selected">50p</option>
</select>
<select name="select_box2" size="1" class="main" id="select_box2">
<option value="true">1p</option>
<option value="false">20p</option>
<option value="false">50p</option>
<option value="false" selected="selected">£2</option>
</select>
<select name="select_box3" size="1" class="main" id="select_box3">
<option value="true">20p</option>
<option value="false" selected="selected">1p</option>
<option value="false">50p</option>
<option value="false">£2</option>
</select>
Here is where I have had an attempt at trying to create the function and assign it to a button.
My logic was to assign variables to the names of the drop down lists.
Then with that variable assign another varible that will reference the value in a drop down list.
However when i run the code nothing happens at all Javascript doesnt seem to disassprove of any code,
but yet nothing happens.
function checkValues(){ // Ive tried applying this to a button so that the statements below should work on click but they do not
</script>
<script type="javascript">
var selectbox = document.getElementById("select_box");
var a = selectbox.options[selectbox.selectedIndex].value;
var selectbox2 = document.getElementById("select_box2");
var b = selectbox2.options[selectbox2.selectedIndex].value;
var selectbox3 = document.getElementById("select_box3");
var c = selectbox3.options[selectbox3.selectedIndex].value;
var selectbox4 = document.getElementById("select_box4");
var d = selectbox4.options[selectbox4.selectedIndex].value;
if (a == "true" && b == "true" && c == "true" && d == "true")
{
alert("Correct you have won press OK for your Reward!")
document.open("Reward.html");
}
else
{
alert("Not right Please try again!");
}
</script>