Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form validation script not firing 1

Status
Not open for further replies.

cdck

Programmer
Nov 25, 2003
281
0
0
US
I have a form which is submitted using a button from an image file. The INPUT settings are:

[tt]<INPUT type="image" src="/graphics/Buttons/bButtonContinue.gif" tabindex="7" onclick="return verifyAddition()">[/tt]

verifyAddition is not firing when I click the button - it is supposed to make certain that certain fields have been filled in or filled in correctly, and not submit the form if they have not. Instead, the form just submits when I click on the image. Below is the javascript that should fire, which is embedded near the top of the page:

[tt]<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function verifyAddition() {
var themessage = "You are required to complete the following fields: ";
if (document.form.exSOFT.value=="0") AND (document.form.nwSoft.value=="") {
themessage = themessage + " - You must either select an existing software or input the name of a new software.";
}
if (document.form.valRev.value=="") {
themessage = themessage + " - You must enter a revision.";
}
if (document.form.valWhen.value=="") {
themessage = themessage + " - You must enter the date the test took place.";
}
if (document.form.valIntent.value=="") {
themessage = themessage + " - You must describe the intended purpose of the software as you've tested it.";
}
if (document.form.valBy.value=="0") {
themessage = themessage + " - You must select the name of the person who tested the software.";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
return true;
//document.form.submit();
}
else {
alert(themessage);
return false;
}
}
// End -->
</script>[/tt]

The script and onclick are identical in execution to the ones I used on another form, which fires correctly. Can anyone see the problem with this code? I'm assuming that I have generated an error in it somewhere.

Cheryl dc Kern
 
If believe the form name used here has to match the actul name of the form:
document.form.exSOFT.value=="0"

So, the form should look like:
<form name="form" ... >
 
Double-checked that:

[tt]<FORM name="form" action="ITL100AddProc.asp" method="post">[/tt]


Cheryl dc Kern
 
I've never used <INPUT type="image" ...> before. Looking it up, it seems like it works the same as a Submit button, which is not what you want to do; you would be better served with a Button, or a hyperlink around an image with an OnClick event.

However, you say you had the same code working elsewhere!?

Below is a simplfied version of your code that works as expected for me. Note that the hyperlink I added will show a javascript error in IE if there are any errors, whereas clicking the image does not show a javascript error for me.

Code:
<HTML><HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function verifyAddition() {
var themessage = "You are required to complete the following fields: ";
if (document.form.valIntent.value=="") {
themessage = themessage + " - You must describe the intended purpose of the software as you've tested it.";
}

//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
alert('data is ok');
return true;
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
//  End -->
</script>
</HEAD><BODY>
<form name="form" method="POST">

<INPUT type="text" name="valIntent">
<INPUT type="image" src="/graphics/Buttons/bButtonContinue.gif" tabindex="7" onclick="return verifyAddition()">
<BR>
<a href='#' onclick="return verifyAddition()">test</a>
</FORM>


</BODY></HTML>
 
Tried adding the link to my code, when I click on the link now, nothing appears to happen at all.
[tt]<INPUT type="image" src="/graphics/Buttons/bButtonContinue.gif" tabindex="7" onclick="return verifyAddition()">
<BR><a href='#' onclick="return verifyAddition()">test</a>[/tt]

Noticed that the script was not in the head section of the page, moved it, no effect on either the image input or the link.

Tested this in both Firefox(where I'm working) and IE, no difference, no errors, even.

Opened the previous project where I had form fields validated, it still functions correctly. Verified again that the call-out for the function is on the image in an identical fashion to this one.

[tt]<INPUT type="image" src="/graphics/Buttons/bButtonContinue.gif" tabindex="23" onclick="return verifyPRStartStep1()">[/tt]

Wondered if my If/AND/then was incorrectly handled, so I commented it out, no effect.

I have to have made some type of bonehead error with placement or typos, but can't for the life of me find it.

Cheryl dc Kern
 
Yea, I don't see the problem either yet. Maybe post more of your code? Maybe seeing more of the context will help.
 
Code:
<% OPTION EXPLICIT %>
<%
dim strConnect, pageTitle, adder, Rev, softID, rstempVals, ValsSQL, exSoft, ConVals, strOptions, strBys

adder = request.Form("adder")
If IsNull(adder) = True Then adder = "S"
If Len(adder)<1 Then adder = "S"

softID = request.Form("exSOFT")
If IsNull(softID) = True Then softID = "0"
If Len(softID)<1 Then softID = "0"

Rev = request.Form("REV")
If IsNull(Rev) = True Then Rev = ""
If Len(Rev)<1 Then Rev = ""

strconnect="DSN=quality"
pageTitle=" | Add a Validation Record"

		ValsSQL = "SELECT SoftName, softID FROM ITsoftValidated;"

		Set ConVals=Server.CreateObject("ADODB.Connection")
		ConVals.Open strConnect
		Set rstempVals = ConVals.Execute(ValsSql)

		If rstempVals.eof Then response.write("NOTHING PULLED")

		strOptions = ""

		Do Until rstempVals.eof

		strOptions = strOptions & "<OPTION VALUE='" & rstempVals(1) & "' "
		If softID = CStr(rstempVals(1)) Then strOptions = strOptions & "SELECTED='Yes'"
		strOptions = strOptions & ">" & rstempVals(0) & "</OPTION>"
		
		rstempVals.movenext
		LOOP

		rstempVals.Close
		Set rstempVals = Nothing
		ConVals.Close
		Set ConVals = Nothing


		ValsSQL = "SELECT LName, FName, UID FROM userListActive ORDER BY LName, FName;"

		Set ConVals=Server.CreateObject("ADODB.Connection")
		ConVals.Open strConnect
		Set rstempVals = ConVals.Execute(ValsSql)

		If rstempVals.eof Then response.write("<OPTION value=''>Alert IT - NOTHING PULLED</OPTION>")

		strBys = ""

		Do Until rstempVals.eof

		strBys = strBys & "<OPTION VALUE='" & rstempVals(2) & "' "
		strBys = strBys & ">" & rstempVals(0) & ", " & rstempVals(1) & "</OPTION>"
		
		rstempVals.movenext
		LOOP

		rstempVals.Close
		Set rstempVals = Nothing
		ConVals.Close
		Set ConVals = Nothing

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="[URL unfurl="true"]http://internal.aydindisplays.com/includes/style.css"[/URL] />
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function verifyAddition() {
var themessage = "You are required to complete the following fields: ";
//if (document.AddRec.exSOFT.value=="0") AND (document.AddRec.nwSoft.value=="") {
//themessage = themessage + " - You must either select an existing software or input the name of a new software.";
//}
if (document.AddRec.valRev.value=="") {
themessage = themessage + " - You must enter a revision.";
}
if (document.AddRec.valWhen.value=="") {
themessage = themessage + " - You must enter the date the test took place.";
}
if (document.AddRec.valIntent.value=="") {
themessage = themessage + " - You must describe the intended purpose of the software as you've tested it.";
}
if (document.AddRec.valBy.value=="0") {
themessage = themessage + " - You must select the name of the person who tested the software.";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
return true;
document.AddRec.submit();
}
else {
alert(themessage);
return false;
   }
}
//  End -->
</script>
<TITLE> Aydin Displays Intranet - Software Validation Record <% response.write(pageTitle) %> </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="Cheryl Kern">
</HEAD>

<BODY background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/backgrounds/ay.gif">[/URL]
<FONT face="Verdana, Arial">
<!--                                Centering Table Start                    /-->
<TABLE width="100%" height="100%" >
<TR align="center" valign="top">
<TD>
<!--                                Border Table Start                    /-->
	<TABLE width="678" bgcolor="white" border="1">
	<TR>
	<TD>
<!--                                White Table Start                    /-->
		<TABLE width="674" border="0">
		<TR>
		<TD><A HREF="[URL unfurl="true"]http://internal.aydindisplays.com"><IMG[/URL] SRC="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/logos/AydinITNet.gif"[/URL] width="676" height="75" border="0" alt="ITNet"></A></TD>
		</TR>
		<TR><TD bgcolor="8C2605" height="3"> </TD></TR>
		<TR>
		<TD align="center">
<!--                                Title Table Start                    /-->
			<TABLE cellpadding="0" cellspacing="0">
				<TR><TD><Font size="+1"><B>IT Test Software Validation Record</B></font> <% response.write(pageTitle) %> </TD><TD><img src="/graphics/pixel.gif" width="10"></TD>
				</TR>
			</TABLE>
<!--                                Title Table End                    /-->
		</TD>
		</TR>
		<TR><TD bgcolor="8C2605" height="3"> </TD></TR>
		<TR>
		<TD>
<!--                                Body Table Start                    /-->
			<TABLE width="674" border="0" cellspacing="0" cellpadding="0">
			<TR valign="top">
			<TD width="205" align="left" rowspan="2">
			<!--              --------------------------------------Menu-------------------------------------------  /-->
				<TABLE width="200" border = "0" cellspacing="0" cellpadding="0">
				<TR>
				<TD width="17" height="30" background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonOptionGreyL.gif">[/URL] </TD>
				<TD width="166" class="but" background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonBodyGrey.gif"[/URL] align="center"><FONT color="000000">Validated Items</FONT></TD>
				<TD width="24"  background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonOpenGreyR.gif">[/URL] </TD>
				</TR>
				<TR>
				<TD width="17" height="30" background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonOptionRedL.gif">[/URL] </TD>
				<TD width="166" class="but" background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonBodyRed.gif"[/URL] align="center"><A class="but" href="[URL unfurl="true"]HTTP://internal.aydindisplays.com/IT/">IT[/URL] Home</A></TD>
				<TD width="24"  background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonOptionRedR.gif">[/URL] </TD>
				</TR>
				<TR>
				<TD width="17" height="30" background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonOptionRedL.gif">[/URL] </TD>
				<TD width="166" class="but" background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonBodyRed.gif"[/URL] align="center"><A class="but" href="[URL unfurl="true"]HTTP://internal.aydindisplays.com/IT/ITL100.asp">Full[/URL] List</A></TD>
				<TD width="24"  background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonOptionRedR.gif">[/URL] </TD>
				</TR>
				<TR>
				<TD width="17" height="30" background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonOptionRedL.gif">[/URL] </TD>
				<TD width="166" class="but" background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonBodyRed.gif"[/URL] align="center"><A class="but" href="[URL unfurl="true"]HTTP://internal.aydindisplays.com/IT/ITL100addition.asp">Add[/URL] a Record</A></TD>
				<TD width="24"  background="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/navigation/ButtonOptionRedR.gif">[/URL] </TD>
				</TR>
				</TABLE>
			<!--              --------------------------------------/Menu-------------------------------------------  /-->

			</TD>
			<TD width="2" align="left" rowspan="2"><IMG src="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/pixel.gif"[/URL] width="4" height="1"></TD>
			<TD><IMG src="[URL unfurl="true"]http://internal.aydindisplays.com/graphics/pixel.gif"[/URL] width="1" height="4"></TD>
			</TR>
			<TR valign="top">
			<TD>

	<P>Under construction: please be patient.</P>
	<FORM name="AddRec" action="ITL100AddProc.asp" method="post">
	<CENTER><TABLE>

	<TR>
	<TD  align=right>Software:</TD>
	<TD>
	<SELECT NAME="exSoft" tabindex="1">
	<OPTION VALUE="0" <% If adder = "S" Then response.write("selected='yes'") %>>New Software</OPTION>	
		<%
		response.write(strOptions)
		%>
	</SELECT>
	</TD>
	</TR>
	<TR>
	<TD align=right>new item:<BR><I><font size=-2>only if not found above</font></I></TD>
	<TD>
	<INPUT TYPE="TEXT" NAME="nwSoft" size="50" maxlength="255" value="">
	</TD>
	</TR>
	<TR>
	<TD align=right>Revision:</TD>
	<TD>
	<INPUT TYPE="TEXT" NAME="ValRev" size="50" maxlength="50" tabindex="2" value="<% response.write(Rev) %>">
	</TD>
	</TR>
	<TR>
	<TD align=right>Tested by:</TD>
	<TD>
	<SELECT NAME="valBy" tabindex="3">
		<OPTION VALUE="0" SELECTED="YES">SELECT YOUR NAME</OPTION>	
		<%
		response.write(strBys)
		%>
	</SELECT>
	</TD>
	</TR>
	<TR>
	<TD align=right>Tested on:</TD>
	<TD>
	<INPUT TYPE="TEXT" NAME="ValWhen" size="10" maxlength="10" tabindex="4" value=" <% response.write(date) %> ">
	</TD>
	</TR>
	<TR valign="top">
	<TD align=right>Intended Use:</TD>
	<TD>
	<TEXTAREA NAME="ValIntent" Rows="4" cols="37" maxlength="500" tabindex="5" value=""></TextArea>
	</TD>
	</TR>
	<TR>
	<TD></TD>
	<TD align=center>
	<INPUT TYPE="Radio" VALUE="-1"" Name="ValResult" checked="yes"> PASS (valid)<font color=white>|---|</font> 
	<INPUT TYPE="Radio" VALUE="0"" Name="ValResult"> FAIL (invalid)
	</TD>
	</TR>
	<TR valign="top">
	<TD align=right>Notes:</TD>
	<TD>
	<TEXTAREA NAME="ValNotes" Rows="4" cols="37" maxlength="500" tabindex="6" value=""></TextArea>
	</TD>
	</TR>
	<TR>
	<TD colspan=2>
	<CENTER><INPUT type="image" src="/graphics/Buttons/bButtonContinue.gif" tabindex="7" onclick="return verifyAddition()"><BR><a href='#' onclick="return verifyAddition()">test</a></CENTER></FORM>
	</TD>
	</TR>
		</TABLE></CENTER>
</TD>
</TR>
</TABLE>
			</TD>
			</TR>
			</TABLE>
<!--                                Body Table End                    /-->
		</TD>
		</TR>
		<TR><TD bgcolor="8C2605" height="3"> </TD></TR>
		<TR>
		<TD>
<!--                                Footer Table Start                    /-->
			<TABLE width="674" border="0" bgcolor="white">
			<TR>
			<TD><font size="-2"><center>Information on these pages is proprietary.-----<%response.write(now)%>-----For internal use/reference only.</center></font></TD>
			</TR>
			</TABLE>
<!--                                Footer Table End                    /-->
			</TD>
			</TR>
			</TABLE>
<!--                                White Table End                    /-->	
	</TD>
	</TR>
	</TABLE>
<!--                                Border Table End                   /-->

</TD>
</TR>
</TABLE>
<!--                                Centering Table End                    /-->

</FONT>
</BODY>
</HTML>

Cheryl dc Kern
 
Now I see. Javascript variables are case-sensitive. You have a textbox named ValRev, but your javascript refers to valRev. Check the others in that function as well.

BTW, running your code above in IE, I did get javascript errors, not sure why you don't. maybe your browser has that turned off?
 
Thank you! I corrected the cases of the variable names, and the script runs correctly - with some further editing on the and statement.

the final code is:
Code:
function verifyAddition() {
var themessage = "You are required to complete the following fields: ";
if (document.AddRec.nwSoft.value==""){
	if (document.AddRec.exSoft.value=="0"){
	themessage = themessage + " - You must either select an existing software or input the name of a new software.";
	}
}
if (document.AddRec.ValRev.value=="") {
themessage = themessage + " - You must enter a revision.";
}
if (document.AddRec.ValWhen.value=="") {
themessage = themessage + " - You must enter the date the test took place.";
}
if (document.AddRec.ValIntent.value=="") {
themessage = themessage + " - You must describe the intended purpose of the software as you've tested it.";
}
if (document.AddRec.ValBy.value=="0") {
themessage = themessage + " - You must select the name of the person who tested the software.";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
return true;
document.AddRec.submit();
}
else {
alert(themessage);
return false;
   }
}



Cheryl dc Kern
 
I have a form , and I have it call itself with a parm stating it was updated when submitted, there is a select case in the asp as follows....(pseudo code / Logic only)

Select case On_update
Case = 1 ' True

'Check all my fields for validation and set error message to vars..

If querystring(var1) = "" then var1_err = "enter zip code please"
' and you can use asp's string functions to split up entries
If querstring(phonenum) = (left(phonenum,3) <> "518" then phonenum_err "your not in the upstate ny area sorry"
.
.
' Check all your fields and set an errflag =1
Case = 1 ' False not update normal form entery

'Display form for entry

end select

if errflag = 1
'Display form and errors you can do this inline with the
. 'reg form display also
.
.
Elseif errflag = 0 'no errors on form submit.

'submit info, update db etc.
.
.
.
End if
 
sorry

If querystring(left,phonenum,3)<> "518" then phonenum_err "your not in the upstate ny area sorry
 
waiting1962:
Please create a new thread, rather than add on to an existing thread. Got the the forum main page here forum333 and scroll to the bottom to create a new thread
 
You're not replying to my thread, you're asking a new question. If you tack it onto the bottom of my thread, people are not likely to pay any attention to it.

Not only is it appropriate etiquette, it's the best way to have a chance of getting an answer; people reading my thread would see that I got my answer and stop reading.

Cheryl dc Kern
 
Cheryl

Notice in My first post, there are no ? at all, sorry , I was only offering up my validation usage on my form as a FYI for the original Post as an Option. Don't want an answer as I asked no question. Mine works, pseudo code not withstanding.

Unless you see something in my post that looks like a ?

Just because you got an answer , should not preclude you from viewing another option on the matter. Thats all I was doing.

Thanks
[ponder]
 
waiting1962:
No worries... It seems that you are new to this forum, so welcome... this is a great forum to learn, get help, and help others.

True, your post did not ask a question, but it also did not seem to offer a solution to the original question either. That's why we assumed you were asking a new question, and that is why we recommended you start a new thread. If you follow each post of this thread, you will see that the original problem was answered, and the solution had to do with javascript being case-sensitive. I'm not seeing how your post offered a better solution.

Again, no worries. I hope you get as much out of this forum as I have over the years. See the link below for some general guidelines and recommendations to get the most out of tek-tips:
faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top