I'm a javascript newbie. I am trying to create a web redirect to a client's development site based on a "Client ID" that they enter.
Here is what I have so far, you'll see I'm going about this completely backwards.
I would like a redirect to the URL in a new tab. BUT if they enter the wrong client ID, an alert pops up 'Sorry, try again.' With the alert added the way I have it, I get a pop-up regardless if they enter the correct 'code' or not.
<head>
<script>
function validateCode()
{
var codeTextBox = document.getElementById("codeTextBox").value;
if (codeTextBox == 'C1')
{
window.location.href = "http://www.client1.com";
}
if (codeTextBox == 'C2')
{
window.location.href = "http://www.client2.com";
}
if (codeTextBox == 'C3')
{
window.location.href = "http://www.client3.com";
}
if (codeTextBox == 'C4')
{
window.location.href = "http://www.client4.com";
} else {
alert('Sorry, try again.');
}
}
</script>
</head>
<body>
Enter User ID:
<input type="text" name="codeTextBox" id="codeTextBox" />
<input type="submit" name="Submit" value="Submit" onclick="validateCode()" />
</body>
Be easy on me guys :) Thanks!
else ifinstead of justifwindow.open(url, '_blank');