Will Bagshaw Will Bagshaw - 2 months ago 10
Javascript Question

Javascript redirect to two thank you pages, depending on form response

There is a yes or no field on the form, depending on user's choice I would like to send them to a different thank you page depending on their answer.

With this, I just get a blank page. I've tried everything I can think of, so I appreciate any insight.



<form action="http://www.google.com/form" name="Lead" id="Lead" class="sem-form" onsubmit="return redirectTY()">

<label class="select">
<select name="Invest_RD" id="Invest_RD">
<option value="Yes">Yes</option>
<option selected="selected" value="No">No</option>
</select></label>
</form>







function redirectTY(){
var qualify = document.getElementById("Invest_RD".value);
if (qualify == "Yes"){
window.location.href='http://www.google.com';
} else {
window.location.href='http://www.bing.com';
}
}




Answer

Your code looks fine, except for this detail:

document.getElementById("Invest_RD".value);

This will crash all your javascript. Probably your console (developer tools) have red messages refered to this. To fix it write:

document.getElementById("Invest_RD").value;

That's because getElementById() is a method of document, and value is a property of the element returned by getElementById().

Comments