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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validation script not working 2

Status
Not open for further replies.

randyQ

IS-IT--Management
Apr 26, 2001
117
US
I have a php page that posts to itself to add records to a DB. In the form tag, I have a 'onSubmit="return CheckForm()"', which should be running prior to the form posting. Below is my CheckForm() function, which is not working. The form just goes ahead and posts itself, and adds the blank record to the database. Any suggestions or help would be greatly appreciated.

Code:
<script type="text/javascript" language="javascript">
<!--
function CheckForm(){
	var tmpError = "Missing Information:"
	var tmpPNF = document.PreKSurvey.frmPrntName_First.value
	var tmpPNL = document.PreKSurvey.frmPrntName_Lastt.value
	var tmpAD1 = document.PreKSurvey.frmAddr_1.value
	var tmpADC = document.PreKSurvey.frmAddr_City.value
	var tmpADS = document.PreKSurvey.frmAddr_St.value
	var tmpADZ = document.PreKSurvey.frmAddr_Zip.value
	var tmpCNF = document.PreKSurvey.frmChldName_First.value
	var tmpCNL = document.PreKSurvey.frmChldName_Last.value
	var tmpCK8 = document.PreKSurvey.frmCheck_8.value
	var tmpC8T = document.PreKSurvey.frmCheck_8_Txt.value

	if(tmpPNF == ""){tmpError += "\nPlease fill out 'Parent First Name'."}
	if(tmpPNL == ""){tmpError += "\nPlease fill out 'Parent Last Name'."}
	if(tmpCNF == ""){tmpError += "\nPlease fill out 'Child First Name'."}
	if(tmpCNL == ""){tmpError += "\nPlease fill out 'Child Last Name'."}
	if(tmpAD1 == ""){tmpError += "\nPlease fill out 'Address 1'."}
	if(tmpADC == ""){tmpError += "\nPlease fill out 'Address City'."}
	if(tmpADS == ""){tmpError += "\nPlease fill out 'Address State (2 letter code)'."}
	if(tmpADZ == ""){tmpError += "\nPlease fill out 'Address Zip'."}
	if(tmpCK8 == "on" && tmpC8T == ""){tmpError += "\nPlease fill out 'Diagnosis'."}

	if(tmpError == "Missing Information:"){return true} else {alert(tmpError); return false;}
}
-->
</script>

Again, thank you for any help given!
 
I would guess that you don't actually have a text input named frmPrntName_Last[red]t[/red] that you refer to on the line that starts:
Code:
var tmpPNL

Lee
 
Also, you should use this syntax:

Code:
document.forms['PreKSurvey']

instead of this syntax:

Code:
document.PreKSurvey

as the latter is a shortcut that might well only work in IE and not many other browsers.

Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Not only it is off the point, it is just imagination.
 
How about making sure the voltage is stable as well?
 
That darn 't' was it, thank you so much trollacious!

Also, thank you BillyRay for the document.forms[] correction! Obviously I have not been keeping up on my javascript standards. And thank you for the note on semicolons, I do agree with you on that. I have been doing so much PHP coding lately, that initially my javascript had semicolons, but when it didn't work, I was like "does JavaScript require semicolons??", and took them out since I wasn't sure.

Again, thank you to all for your help, as always, I am greatly thankful for the level of support and kindness by the members of this site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top