Jump to content

Select values and if then statements


Rominall

Recommended Posts

I have a table w/ 4 columns: col 1 = string; col 2 = selection w/ 5 options, col 3 = selection w/ 5 options, col 4 =button. I want to have the user select an option in both col 2 & 3 and then click the button to 'check' the options selected. Here's the HTML for the table <tr><td class="Prod">Product1</td> <select name="mySelect1"; onchange="ChckValue()"><option value="3">Choose</option><option value="1">$7.95</option><option value="1">$9.95</option><option value="2">$12.95</option><option value="1">$14.95</option></select> </td> <td class="Prod">Product2</td><select name="mySelect2"; onchange="ChckValue()"><option value="3">Choose</option><option value="1">$7.95</option><option value="1">$9.95</option><option value="2">$12.95</option><option value="1">$14.95</option></select> </td> <td class="ChkBtn"><button class="ChkBtn"; onclick="Validate(this)">Check</button></td> </tr> I'm doing this in stages so currently when they change a value in either select I want to make sure it's getting the right "value". However it seems to only be picking up a value of 1. Here's the Javascriptfunction ChckValue() {var selected = mySelect.options[mySelect.selectedIndex].value;if (selected = "1") { alert("The answer is wrong.")}else if (selected = "2"){ alert("The answer is right.")} } I've tried the selected = with and without quotes. Is it something like I can't have the same 'value' for multiple options? This is for a quiz so it's be nice if I could have multiple 'wrong' values and not have to distinguis the wrong values. Any help???

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...