Will the form be submitted after onclick event

H

hon123456

Dear all,

Suppose I have a form as follows:

<script>
functionABC()
{ alert("Hello world")}
</script>

<form name="form1" action="test.php" method="post">
<input type="submit" value="submit" onclick = "functionABC">
</form>

My question is : When I press the submit button, after the
onclick function is executed, will the form be submitted too following
the execution of onclick function? Thanks.
 
E

Evertjan.

hon123456 wrote on 09 jan 2007 in comp.lang.javascript:
Dear all,

Suppose I have a form as follows:

<script>
functionABC()
{ alert("Hello world")}
</script>

<form name="form1" action="test.php" method="post">
<input type="submit" value="submit" onclick = "functionABC">

better:

onclick = "functionABC();return true;"
</form>

My question is : When I press the submit button, after the
onclick function is executed, will the form be submitted too following
the execution of onclick function? Thanks.

Did you test this?
 
J

jiverbean

Evertjan. said:
hon123456 wrote on 09 jan 2007 in comp.lang.javascript:


better:

onclick = "functionABC();return true;"
Whay is onclick = " functionABC();return true;" better? Are there
browsers who don't support the built-in submit event? Would it not
submit if we write return false?

I would like to suggest the following:

<script>
functionABC(myForm)
{ alert("Hello world")
myForm.submit(); }
</script>

<form name="form1" action="test.php" method="post">
<input type="button" value="submit" onclick = "functionABC">
</form>

Iassume this only works if JavaScript is enabled, but I always like to
do field validation on forms.
Regards,
jiverbean
Luxembourg
 
E

Evertjan.

jiverbean wrote on 09 jan 2007 in comp.lang.javascript:
Whay is onclick = " functionABC();return true;" better? Are there
browsers who don't support the built-in submit event?
Would it not submit if we write return false?

Indeed, you got it.
I would like to suggest the following:

<script>

functionABC(myForm)
{ alert("Hello world")
myForm.submit(); }
</script>

<form name="form1" action="test.php" method="post">
<input type="button" value="submit" onclick = "functionABC">
</form>

Problem one: not functionABC but functionABC()

Problem two: this would do a "double submit" where the js submit and the
html submit each could fire first.

My advice here:

onclick = "functionABC();return false;"

If you had added terget='_blank' to the <form and [corrected the ()],
you could probably see the double submit easily.

Iassume this only works if JavaScript is enabled,

Yes JS works only when enabled.
but I always like to do field validation on forms.

Is this on topic?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top