Rominall Posted July 20, 2012 Share Posted July 20, 2012 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 More sharing options...
Don E Posted July 20, 2012 Share Posted July 20, 2012 For the if statements conditionals, when checking if something is equal-to, you use two equal signs: == Example:if(selected == "1") See if that helps. Link to comment Share on other sites More sharing options...
Rominall Posted July 20, 2012 Author Share Posted July 20, 2012 Well I feel stupid. THANKS!!!!! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now