Javascript Go To A Url If User Input A Specific Number Else Go To Another Url
I want if user input on id input-code is only 1234abc, then then he'll be redirected to Google. If he enter anything else, then he'll be redirected to Bing. My HTML:
Solution 1:
You're declaring the same function twice, so it is running the last defined version. And because your code is not in a function or bound to an event it runs on page load. Try this:
function btntest_onclick(){
if (document.getElementById('input-code').value == '1234') {
window.location.href = "http://www.google.com";
} else {
window.location.href = "http://www.bing.com";
}
};
Post a Comment for "Javascript Go To A Url If User Input A Specific Number Else Go To Another Url"