earwig75
asked on
Javascript Validation, only run if first choice is true
I am using the below to validate two drop downs. If the first drop down (choice1) is Yes, I want the code to compare that dropdown with the next (choice2). If Choice1 is No, I don't want anything to happen. I know my sample isn't complete... and for some reason after running it changes both choices to be the same. Forgive me as I am not that great with javascript and still learning. Can someone assist?
function DoCustomValidation()
{
var frm = document.forms["MyForm"];
if(frm.Choice1.value = frm.Choice2.value)
{
sfm_show_error_msg('They match!',frm.Choice1);
return false;
}
else
{
return true;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
A single = is used for assignment, you need two == to compare:
Open in new window