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

onSubmit="return checksubmit()"

Status
Not open for further replies.

JohannIcon

Programmer
Sep 3, 2002
440
MT
Hi All,

I have an error in my validation page however I cannot understand why cause I think I am doing everything right. My error is onSubmit, and the funny thing is that I am using the same code as another ASP page and the other ASP is working!

The error the browser is giving me is Object Expected and pointing the the onSubmit action!

Here is my code:-

<form name=&quot;SendForm&quot; method=&quot;post&quot; action=&quot;ContactForm.asp&quot; onSubmit=&quot;return checksubmit()&quot;>
<table width=&quot;320&quot; border=&quot;0&quot; align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td width=&quot;68&quot; height=&quot;25&quot; class=&quot;textgrey&quot;>Name:</td>
<td width=&quot;270&quot; class=&quot;textgrey&quot;>
<input name=&quot;firstName&quot; type=&quot;text&quot; id=&quot;firstName&quot; size=&quot;35&quot; class=&quot;textgrey&quot;>
</td>
</tr>
<tr>
<td class=&quot;textgrey&quot;>Surname:</td>
<td> <input name=&quot;Surname&quot; type=&quot;text&quot; id=&quot;surname&quot; size=&quot;35&quot; class=&quot;textgrey&quot;>
</td>
</tr>
<tr>
<td class=&quot;textgrey&quot;>E-Mail:</td>
<td> <input name=&quot;Email&quot; type=&quot;text&quot; id=&quot;eMail&quot; size=&quot;35&quot; class=&quot;textgrey&quot; onChange=&quot;return validate_email(SendForm.Email)&quot;>
</td>
</tr>
<tr>
<td class=&quot;textgrey&quot;>Message:</td>
<td><textarea name=&quot;Message&quot; cols=&quot;35&quot; rows=&quot;6&quot; class=&quot;textgrey&quot; id=&quot;message&quot;></textarea></td>
</tr>
</table>
<p align=&quot;right&quot;>&nbsp;</p>
<input type=&quot;hidden&quot; name=&quot;hiddenField&quot; value=&quot;Query from Client&quot;>
<center>
<input name=&quot;submit&quot; type=&quot;submit&quot; class=&quot;menu&quot; value=&quot;Send&quot;>
</center>
</form>

<script>
function checksubmit() {

if (SendForm.firstName.value == &quot;&quot;)
{
alert(&quot;You must Enter Your Name&quot;)
SendForm.firstName.focus()
SendForm.firstName.select()
return false
}
.
.
.
.
.
. return true
}

Can you tell me if you find anything weird?
 
<script>
function checksubmit() {

if (SendForm.firstName.value == &quot;&quot;)
{
alert(&quot;You must Enter Your Name&quot;)
SendForm.firstName.focus()
SendForm.firstName.select()
//How can you select when it is blank? -- sometimes this MAY throw an error
return false
}
.
.
.
.
.
. return true
}
-- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
first, try that :
<form name=&quot;SendForm&quot; method=&quot;post&quot; action=&quot;ContactForm.asp&quot; onSubmit=&quot;return checksubmit();&quot;>

And then, in your script, why don't you use &quot;getElementById&quot; function like this :
Code:
<script>
function checksubmit()    {
    var obj = document.getElementById(&quot;firstName&quot;);
    if (obj.value == &quot;&quot;)
    {
        alert(&quot;You must Enter Your Name&quot;);
        obj.focus();
        obj.select();
        return false;
    }
.
NOTE : is it normal that you didn't put any semicolons (&quot;;&quot;) at end of lines ??? Water is not bad as long as it stays out human body ;-)
 
I am not getting this error. I copied and pasted your code and the only change I made was moving the script into the head section. Is it possible you have an error in your javascript function below what you have show that is invalidating it?
ALso, just to make me feel better, could you move it into thte head section of the code just to check?
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Wow, it worked while moving the code on the top! Funny, very funny!
 
The location of the script is important still :) Amazing. I actually didn't think that would work, but I am glad it did, and we all learned that location still matters to scripting, cool.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Yeah but it is still funny I think, since it is javascript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top