Forum Moderators: open
I have two conditions to be tested and have written them in individual functions, but how do I get them to both run together?
Do I put them together in one function that calls both or do I set up if/else statements?
here is my code :
<!--
function validateEmpty(objcontrol)
{
var result = true;
//alert("hello world");
if (objcontrol.value == "" ¦¦ objcontrol == null){
alert("please enter something in");
objcontrol.focus();
objcontrol.select();
result = false;
}
return result;
}
function validateNumber(objcontrol)
{
var ValidChars = "0123456789.";
var result = true;
var Char;
var mystring = objcontrol.value
// alert(mystring.length);
for (i = 0; i < mystring.length && result == true; i++)
{
Char = mystring.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
alert("Please enter numbers only");
objcontrol.focus();
objcontrol.select();
result = false;
}
}
return result;
}
-->
</script>
<form name="searchResult2" action="../donewPermitSearch.asp" method=POST onSubmit="javascript:return validateEmpty(this.PermitNO)" >
__________________
Colleen
In pseudo-code, you could do this:
if condition 1 fails
then alert something and return false;
if condition 2 fails
then alert something and return false;
return false will exit the function, so there is no need for complicated if-else constructions.
[edited by: RonPK at 4:57 pm (utc) on Oct. 8, 2003]
function validateEmpty(objcontrol)
{
var result = true;
//alert("hello world");
if (objcontrol.value == "" ¦¦ objcontrol == null){
alert("please enter something in");
objcontrol.focus();
objcontrol.select();
return false;
}
validateNumber(objcontrol);
}
This will return false if the first check fails, otherwise it will call the second function (which will return either true or false).