By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

submitting a page

P: n/a
I have the following:

<input type="image" src="images/submit.jpg" width="70" height="30"
border="0" onclick="validateRegister()" />

It is inside a form where:

<form action="register_submit.php" name="register" id="register"
method="post">

At the end of validateRegister() I have:

if (msg.length 0) {
alert(msg);
} else {
document.register.submit();
}

after having built the msg based upon any errors. (It starts with
var msg = '';)

What I am happening is that it alerts the message of all the errors
because msg.length 0, but then it submits the page!!! Even if I
comment out the document.register.submit(), it still submits it.

How can it submit the page if not a single call is made to post and
there is not button for submit?
Jun 27 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
* sheldonlg wrote in comp.lang.javascript:
>What I am happening is that it alerts the message of all the errors
because msg.length 0, but then it submits the page!!! Even if I
comment out the document.register.submit(), it still submits it.
You have to prevent the default action of the submit event. Methods how
to do that vary between browsers, one way to do it would be to call the
..preventDefault() method on the event object where available. Another
would be to `return false` from the code in the onsubmit attribute.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 27 '08 #2

P: n/a
sheldonlg <sheldonlgwrote in
news:yp******************************@giganews.com :
I have the following:

<input type="image" src="images/submit.jpg" width="70" height="30"
border="0" onclick="validateRegister()" />
Remove the onclick on the image submit.
It is inside a form where:

<form action="register_submit.php" name="register" id="register"
method="post">
Add onsubmit="return validateRegister();" to the form.
At the end of validateRegister() I have:

if (msg.length 0) {
alert(msg);
add return false;
} else {
document.register.submit();
replace document.register.submit();
with return true;
}

after having built the msg based upon any errors. (It starts with
var msg = '';)

What I am happening is that it alerts the message of all the errors
because msg.length 0, but then it submits the page!!! Even if I
comment out the document.register.submit(), it still submits it.
Input type="image" is your submit button.
How can it submit the page if not a single call is made to post and
there is not button for submit?
Your submit button is the input image.

Javascript validation is only a courtesy to the user, do validate on the
server.

--
BootNic Tuesday May 20, 2008 8:35 PM
Don't worry about people stealing an idea. If it's original, you
will have to ram it down their throats.
*Howard Aiken*
Jun 27 '08 #3

P: n/a
BootNic wrote:
sheldonlg <sheldonlgwrote in
news:yp******************************@giganews.com :
>I have the following:

<input type="image" src="images/submit.jpg" width="70" height="30"
border="0" onclick="validateRegister()" />

Remove the onclick on the image submit.
>It is inside a form where:

<form action="register_submit.php" name="register" id="register"
method="post">

Add onsubmit="return validateRegister();" to the form.
>At the end of validateRegister() I have:

if (msg.length 0) {
alert(msg);

add return false;
>} else {
document.register.submit();

replace document.register.submit();
with return true;
>}

after having built the msg based upon any errors. (It starts with
var msg = '';)

What I am happening is that it alerts the message of all the errors
because msg.length 0, but then it submits the page!!! Even if I
comment out the document.register.submit(), it still submits it.

Input type="image" is your submit button.
Thanks.
>
>How can it submit the page if not a single call is made to post and
there is not button for submit?

Your submit button is the input image.
Uh, no, not the way I had it coded. All it is is a button that invokes
a javascript. It knows nothing about submitting.
>
Javascript validation is only a courtesy to the user, do validate on the
server.
Jun 27 '08 #4

P: n/a
Bjoern Hoehrmann wrote:
* sheldonlg wrote in comp.lang.javascript:
>What I am happening is that it alerts the message of all the errors
because msg.length 0, but then it submits the page!!! Even if I
comment out the document.register.submit(), it still submits it.

You have to prevent the default action of the submit event. Methods how
to do that vary between browsers, one way to do it would be to call the
.preventDefault() method on the event object where available. Another
would be to `return false` from the code in the onsubmit attribute.
How is the default action being invoked? Nothing is labeled "submit"
for a type and the submit() is not called.
Jun 27 '08 #5

P: n/a
BootNic wrote:
sheldonlg <sheldonlgwrote in
news:yp******************************@giganews.com :
>I have the following:

<input type="image" src="images/submit.jpg" width="70" height="30"
border="0" onclick="validateRegister()" />

Remove the onclick on the image submit.
>It is inside a form where:

<form action="register_submit.php" name="register" id="register"
method="post">

Add onsubmit="return validateRegister();" to the form.
>At the end of validateRegister() I have:

if (msg.length 0) {
alert(msg);

add return false;
>} else {
document.register.submit();

replace document.register.submit();
with return true;
That worked. Thanks.
Jun 27 '08 #6

P: n/a
sheldonlg escribió:
How is the default action being invoked? Nothing is labeled "submit"
for a type and the submit() is not called.
<input type="image" src="images/submit.jpg" width="70" height="30"
border="0" onclick="validateRegister()" />

http://www.w3.org/TR/html401/interac....html#h-17.4.1
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #7

P: n/a
Álvaro G. Vicario wrote:
sheldonlg escribió:
>How is the default action being invoked? Nothing is labeled "submit"
for a type and the submit() is not called.

<input type="image" src="images/submit.jpg" width="70" height="30"
border="0" onclick="validateRegister()" />

http://www.w3.org/TR/html401/interac....html#h-17.4.1
Yes, I just learned this yesterday. I thought that the only submit was
through a submit button and that all else was handled by
control.submit(). Thanks.
Jun 27 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.