I have a drop down- If user tries to submit the page, but doesn't choose an option from the dropdown, then I want an ALERT message box to appear, then for the page to stay where it is instead of navigating to another page.
Currently, the drop down appears, but the page still redirects to another page. How do I prevent this?
I tried "return false" but it didn't work...
function validateDropDown() {
var e = document.getElementById("colors"); var strUser = e.options[e.selectedIndex].value;
var strColor1 = e.options[e.selectedIndex].text;
var strColor = e.options[e.selectedIndex].text;
if(strColor==0)
{
alert("Please select a color");
return false;//This is what I tried to prevent page redirection, but it doesn't work.
}
}