I don't know if anyone could have a quick look at the validation below as I have spent hours trying to get it to work without success. The general gist is that there is 5 text boxes that have various checks before submitting. The field ward checks the entry against and array. There is two submit buttons and depending on which is selected the form is sent to different locations. It works if I use each validation separately but only partially works when combined. I suspect I have made a school boy error somewhere. Can anyone double check my logic.
thanks
<HTML>
<HEAD>
<TITLE>New Patient</TITLE>
<script>
<!--
function setFocus() {
document.Newpatient.Ward.focus();
}
//-->
</script>
<SCRIPT>
function submitFunction(i)
{
var titles = new Array("A1", "A2", "A3", "A4");
var titleValid = false;
var theTitle = document.Newpatient.Ward.value.toUpperCase();
for(var x=0; x<titles.length; x++)
{
if(theTitle == titles[x])
{
titleValid = true;
}
}
var returnValue = false;
if(!titleValid)
{
alert("That wasn't a valid ward please try again");
document.Newpatient.Ward.focus();
}
else if (document.Newpatient.Ward.value == "")
{
alert("please enter a value for ward");
document.Newpatient.Ward.focus();
}
else if(document.Newpatient.Item.value < 0)
{
alert("please enter a value greater than zero");
document.Newpatient.Item.focus();
}
else if(document.Newpatient.Item.value == "")
{
alert("please enter a value ");
document.Newpatient.Item.focus();
}
else if(document.Newpatient.fname.value == "")
{
alert("please enter a first name");
document.Newpatient.fname.focus();
}
else if(document.Newpatient.Surname.value == "")
{
alert("please enter a surname");
document.Newpatient.Surname.focus();
}
else if(document.Newpatient.Item.value >= 25)
{
alert("maximum number of items allowed is 25");
document.Newpatient.Item.focus();
}
else returnValue = true;
{
return returnValue;
}
if (i==1) document.Newpatient.action=
"if (i==2) document.Newpatient.action=
"wrpatupdate.asp";;
document.Newpatient.submit()
}
</SCRIPT>
</HEAD>
<BODY onLoad="setFocus()">
<P ALIGN="center">Enter Prescription Details<BR>
<CENTER>
<FORM ACTION="METHOD="POST"
NAME=Newpatient
onclick="return Newpatient_onsubmit()">
<TABLE BORDER=0 WIDTH="553">
<TABLE BORDER=0 WIDTH="553">
<TR>
</CENTER>
<TD WIDTH="164">
<P ALIGN="right"><INPUT TYPE="CHECKBOX" Name="pharwrit" value="ON"><FONT SIZE="1">Tick if written by pharmacist</FONT></P>
</TD>
</TR>
<CENTER>
<TR>
<TD WIDTH="161" ALIGN="right">Ward:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="Ward" SIZE="6" tabindex="1">
<FONT SIZE="1"> i.e For "urology" enter "a2", "neonates" enter
"SCB"</FONT></TD>
</TR>
<TR>
<TD WIDTH="161" ALIGN="right">First Name:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="fname" Value="<%=fname%>"
SIZE="21" tabindex="2"></TD>
</TR>
<TR>
<TD WIDTH="161" ALIGN="right">Surname:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="Surname" Value="<%=surname%>"
SIZE="26" tabindex="3"></TD>
</TR>
<TR>
<TD WIDTH="161" ALIGN="right">Items:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="Item"
SIZE="4" tabindex="4"></TD>
</TR>
<TR>
<TD WIDTH="161" ALIGN="right">Notes:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="note"
SIZE="40" tabindex="7"><FONT SIZE="1"> <BR>
Field can be left blank</FONT></TD>
</TR>
<TR>
<TD WIDTH="161"><input type="checkbox" name="dispward" value="ON"><font size="1">Tick
if dispensed on ward</font></TD>
<TD ALIGN=CENTER WIDTH="328" COLSPAN="2"><BR>
<INPUT TYPE="button" VALUE="with check" onClick="submitFunction(1)" tabindex="5">
<INPUT TYPE="button" VALUE="no check" onClick="submitFunction(2)" tabindex="6"> <INPUT TYPE="RESET"></TD>
</TR>
</TABLE>
</FORM>
<HR>
<H3><A HREF="menumain.asp"><FONT SIZE="2">Back to Menu</FONT></A></H3>
</CENTER>
</HTML>
thanks
<HTML>
<HEAD>
<TITLE>New Patient</TITLE>
<script>
<!--
function setFocus() {
document.Newpatient.Ward.focus();
}
//-->
</script>
<SCRIPT>
function submitFunction(i)
{
var titles = new Array("A1", "A2", "A3", "A4");
var titleValid = false;
var theTitle = document.Newpatient.Ward.value.toUpperCase();
for(var x=0; x<titles.length; x++)
{
if(theTitle == titles[x])
{
titleValid = true;
}
}
var returnValue = false;
if(!titleValid)
{
alert("That wasn't a valid ward please try again");
document.Newpatient.Ward.focus();
}
else if (document.Newpatient.Ward.value == "")
{
alert("please enter a value for ward");
document.Newpatient.Ward.focus();
}
else if(document.Newpatient.Item.value < 0)
{
alert("please enter a value greater than zero");
document.Newpatient.Item.focus();
}
else if(document.Newpatient.Item.value == "")
{
alert("please enter a value ");
document.Newpatient.Item.focus();
}
else if(document.Newpatient.fname.value == "")
{
alert("please enter a first name");
document.Newpatient.fname.focus();
}
else if(document.Newpatient.Surname.value == "")
{
alert("please enter a surname");
document.Newpatient.Surname.focus();
}
else if(document.Newpatient.Item.value >= 25)
{
alert("maximum number of items allowed is 25");
document.Newpatient.Item.focus();
}
else returnValue = true;
{
return returnValue;
}
if (i==1) document.Newpatient.action=
"if (i==2) document.Newpatient.action=
"wrpatupdate.asp";;
document.Newpatient.submit()
}
</SCRIPT>
</HEAD>
<BODY onLoad="setFocus()">
<P ALIGN="center">Enter Prescription Details<BR>
<CENTER>
<FORM ACTION="METHOD="POST"
NAME=Newpatient
onclick="return Newpatient_onsubmit()">
<TABLE BORDER=0 WIDTH="553">
<TABLE BORDER=0 WIDTH="553">
<TR>
</CENTER>
<TD WIDTH="164">
<P ALIGN="right"><INPUT TYPE="CHECKBOX" Name="pharwrit" value="ON"><FONT SIZE="1">Tick if written by pharmacist</FONT></P>
</TD>
</TR>
<CENTER>
<TR>
<TD WIDTH="161" ALIGN="right">Ward:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="Ward" SIZE="6" tabindex="1">
<FONT SIZE="1"> i.e For "urology" enter "a2", "neonates" enter
"SCB"</FONT></TD>
</TR>
<TR>
<TD WIDTH="161" ALIGN="right">First Name:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="fname" Value="<%=fname%>"
SIZE="21" tabindex="2"></TD>
</TR>
<TR>
<TD WIDTH="161" ALIGN="right">Surname:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="Surname" Value="<%=surname%>"
SIZE="26" tabindex="3"></TD>
</TR>
<TR>
<TD WIDTH="161" ALIGN="right">Items:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="Item"
SIZE="4" tabindex="4"></TD>
</TR>
<TR>
<TD WIDTH="161" ALIGN="right">Notes:</TD>
<TD WIDTH="328" COLSPAN="2"><INPUT NAME="note"
SIZE="40" tabindex="7"><FONT SIZE="1"> <BR>
Field can be left blank</FONT></TD>
</TR>
<TR>
<TD WIDTH="161"><input type="checkbox" name="dispward" value="ON"><font size="1">Tick
if dispensed on ward</font></TD>
<TD ALIGN=CENTER WIDTH="328" COLSPAN="2"><BR>
<INPUT TYPE="button" VALUE="with check" onClick="submitFunction(1)" tabindex="5">
<INPUT TYPE="button" VALUE="no check" onClick="submitFunction(2)" tabindex="6"> <INPUT TYPE="RESET"></TD>
</TR>
</TABLE>
</FORM>
<HR>
<H3><A HREF="menumain.asp"><FONT SIZE="2">Back to Menu</FONT></A></H3>
</CENTER>
</HTML>