GuyPhempoompanitch
Programmer
Please help me. I can't seem to find what is not correct here. Basically I'm trying to stop the form from being submitted if the alert box is shown. Thanks.
FORM:
<form name="search" method="post" action="search/dsp_searchResults.cfm" onsubmit="checkWR(document.getElementById('RequestId').value);" target="Main">
Quick Search: <input type="text" name="RequestID" id="RequestId" value="WR Number" onFocus="this.value='';" class="searchInput"><br>
</form>
JS:
<script language="JavaScript">
function checkWR(sText)
{
var ValidChars = "0123456789,";
var Char;
for (i = 0; i < sText.length; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
alert("Please enter only numbers in the Number field";
return false;
}
}
}
</script>
FORM:
<form name="search" method="post" action="search/dsp_searchResults.cfm" onsubmit="checkWR(document.getElementById('RequestId').value);" target="Main">
Quick Search: <input type="text" name="RequestID" id="RequestId" value="WR Number" onFocus="this.value='';" class="searchInput"><br>
</form>
JS:
<script language="JavaScript">
function checkWR(sText)
{
var ValidChars = "0123456789,";
var Char;
for (i = 0; i < sText.length; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
alert("Please enter only numbers in the Number field";
return false;
}
}
}
</script>