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

why would i get an error when submitting?

Status
Not open for further replies.

storm1976

Programmer
Jul 6, 2001
31
GB
hi,

here is my code for a basic form validation.

the problem occurs when all the validation is fine. an error on the submit line saying the object doesnt support the property or method. i tested it out with an alert and this seems to work alrighty but the submit doesnt like it at all.

<script language=&quot;JavaScript&quot;>
function validateForm() {
var okSoFar=true //-- Changes to false when bad field found.
//-- Check the Name field, reject if blank.
if (document.myForm.txt_name.value==&quot;&quot;) {
okSoFar=false
alert(&quot;All parts of the form must be completed correctly before we can accept an online enquiry.&quot;)
document.myForm.txt_name.focus()
}
//-- Check the email field, reject if blank.
else if (document.myForm.txt_email.value==&quot;&quot;) {
okSoFar=false
alert(&quot;All parts of the form must be completed correctly before we can accept an online enquiry.&quot;)
document.myForm.txt_email.focus()
}
//-- Check the age field, reject if blank.
else if (document.myForm.txt_age.value==&quot;&quot;) {
okSoFar=false
alert(&quot;All parts of the form must be completed correctly before we can accept an online enquiry.&quot;)
document.myForm.txt_age.focus()
}
//-- Check the Enquiry field, reject if blank.
else if (document.myForm.txt_comment.value==&quot;&quot;) {
okSoFar=false
alert(&quot;All parts of the form must be completed correctly before we can accept an online enquiry.&quot;)
document.myForm.txt_comment.focus()
}
//-- If all fields OK go ahead and submit the form and put up a message.
else if {
//-- The statement below actually submits the form, if all OK.
document.myForm.Submit()
}
}
</script>

cheers in advance
storm
 
is this suppose to be a else instead of a else if?

else if {
//-- The statement below actually submits the form, if all OK.
document.myForm.Submit() _________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
Javascript is case-sensitive:

Code:
document.myForm.submit()
--James
 
i did the changes to the code and it still come up with the same error.

have used it as lower case and also

else if (okSoFar==true) {
//-- The statement below actually submits the form, if all OK.
document.myForm.submit()

and

else {
//-- The statement below actually submits the form, if all OK.
document.myForm.submit()

 
Why don't you change your technique slightly and use a return from the function rather than the variable:

Code:
<script language=&quot;javascript&quot;>
<!--
function validForm() {
  if(myForm.txt1.value == &quot;&quot;)
    {alert(&quot;Put something in txt1&quot;);
    myForm.txt1.focus();
    return false;}

  if(myForm.txt2.value == &quot;&quot;)
    {alert(&quot;Put something in txt2&quot;);
    myForm.txt2.focus();
    return false;}
}
//-->
</script>

...

<form name=&quot;myForm&quot; action=&quot;nextpage.asp&quot; method=&quot;post&quot; onSubmit=&quot;return validForm();&quot;>
<input type=&quot;text&quot; name=&quot;txt1&quot;>
<input type=&quot;text&quot; name=&quot;txt2&quot;>
<input type=&quot;submit&quot; name=&quot;submit&quot;>
</form>
--James
 
cheers james after a bit of tweaking etc. it worked a treat.

thanks again
Storm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top