473,395 Members | 1,949 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,395 software developers and data experts.

submitting a page

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
7 1376
* 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
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
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
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
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
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
Á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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mats | last post by:
Hi Maybee a little bit of topic, but is it possible to stay on the submitting page once you've clicked submit. This is to get processing done on page B when you submit on page A, and the page...
2
by: belzibob | last post by:
I have inherited a table where each row is a <form> Each of these rows has only four columns, those being: 1) Item number 4) Quantity (blank textbox to fill in) 3) Description 4) Add link (to...
1
by: Display Name | last post by:
the customer I'm developing a site for uses a canned form-parsing page that allows her to have an email subscription opt-in page add emails to a list she can manage using a link that you point your...
2
by: Greg T | last post by:
Hi, I have a rather long form that I don't want people submitting unless they are absolutely sure they are ready. I figured the easiest way to prevent an accidental form submission by way of...
5
by: Don | last post by:
I have a need to submit a form, but don't need the user to click on a button. How do I do this? Is there some way, using JavaScript, to setup a <form> tag to do this? Thanks, Don ----==...
0
by: Mike Kingscott | last post by:
Totally hacked off here. I've written a user control that contains a text box, a required field validator and a button (these being the cornerstone of a search facility), all as ASP.Net server...
2
by: Syam | last post by:
Hello everyone, I am just barely two months old into learning asp.net and vb.net. Currently I am working on a project to store customer database. I have a question about creating a preview page:...
1
by: Hello | last post by:
Scenario: A page creates a pop up and that pop up submits a form. Is there a way to detect whether the submitting was successful or not, so true/false could be passed to the parent window?
1
by: SachinBhargava | last post by:
Hi, I am faceing the problem while submitting the same page in ASP. When i am submitting the page, I am showing the java script alert message before closing the pop up window. My problem is, when...
3
by: Ken Shimizu | last post by:
I get an error when submitting an .ASPX page in Safari beta, MAC and PC document.getElementbyId(‘FolderBrowser’).submit(); After the server side code has executed without problems I get the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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.