473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Will the form be submitted after onclick event

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.

Jan 9 '07 #1
4 1929
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?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 9 '07 #2

Evertjan. wrote:
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;"
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

Jan 9 '07 #3
"jiverbean" <je********@internet.luwrote:
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;"
Whay is onclick = " functionABC();return true;" better?
It is 'better' in the sense that it actually calls the function rather than
just referencing the function object without calling it. Or at least it
would be better if there was a functionABC defined somewhere to call.

Your script, in case you hadn't realised it contains a call to
functionABC() followed by a block calling alert(). It doesn't actually
contain a function definition. Also it is missing the type attribute, but
that wouldn't stop it running.
Jan 9 '07 #4
jiverbean 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?
Indeed, you got it.
>
I would like to suggest the following:

<script>
<script type='text/javascript'>
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?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: shank | last post by:
I've got 2 problems. Problem #1: I have 2 buttons on a form. If user clicks on ButtonA, the form gets submitted to PageA. If user clicks on ButtonB, the form gets submitted to PageB. One forum...
4
by: Andrew Williams | last post by:
Does anyone know of a way to quickly validate an HTML web form? I need to make sure that certain fields on my form actually contain data and are not submitted blank. I have tried using...
1
by: Orest Kinasevych | last post by:
Okay, I made sense of the earlier suggestions and realized I was on the right track -- I appreciate the feedback which got me to this point. The suggestions posted here indeed worked and...
2
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
6
by: stellstarin | last post by:
I have a HTML page containing two submit buttons in the same form.When the form is submitted,I want to know through which submit button the form was submitted. Is there any event or property which...
9
by: MS | last post by:
I want to be able to use the onclick event to exit a form without submitting any data. How do I do this? This sounds simple but I am having problems finding a solution. Thanks.
0
by: Neal | last post by:
Hi All, Help please Cross browser and W3C issues: Having major hassles trying to get my site working and looking decent in FFox (great in IE), MOzzie support said to try the W3C Validator so...
4
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.