473,748 Members | 8,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Submitting forms with Javascript/Konqueror

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 hitting of the enter key was to simply not have a submit button,
instead going for a regular anchor which calls a javascript confirmation
box and then submits the form.

To do this, I have one function, and an anchor that calls it:

function submitConfirm()
{
var submitConfirmed = confirm("Are you ready to submit this form?");
if( submitConfirmed == true )
{
document.survey Form.submit();
}
....
}

<a href="#" onclick="submit Confirm()"><img src="submitBtn. png"
alt="Submit"></a>
All works fine in Mozilla and IE, but Konqueror doesn't behave as
expected. Instead of submitting the form, the anchor (in this case,
'http://my.site/BrokenSurvey.ht ml#') is loaded instead.

I tried it using getElementsByNa me, but with the same result.

Am I doing something wrong, or is it time to file a bug report with the
KDE folks?

thanks,
Greg
Jul 23 '05 #1
2 2220
Greg T wrote:
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 hitting of the enter key was to simply
not have a submit button, instead going for a regular
anchor which calls a javascript confirmation box and then
submits the form.
You figured wrong. There is one obvious, simple and universally
supported (subject of JS availability) palace to intercept the
submission of any form and that is the - onsubmit - handler of the FORM
element.

With its use you can have the submit button that you should have (thus
avoiding any JS dependency in this aspect of the system, and
inconsistencies in the handling of your approach).

<form name="surveyFor m" action=" ... " method="post"
onsubmit="retur n confirm('Are you ready to submit this form?');">
To do this, I have one function, and an anchor that calls it:

function submitConfirm()
{
var submitConfirmed = confirm("Are you ready to submit this form?");
if( submitConfirmed == true )
{
document.survey Form.submit();
}
...
}
Would have been simpler as:-

function submitConfirm() {
if(confirm("Are you ready to submit this form?")){
document.survey Form.submit();
}
}
<a href="#" onclick="submit Confirm()"><img
src="submitBtn. png" alt="Submit"></a>
When an - onclick - handler does not return boolean false it is not
cancelling the navigation specified in the HREF. It is normal for
browsers to assume that the last interaction with a page in terms of
form submitting or navigation represents the user's current desire. So
navigating to the specified HREF should be the expected result of this
operation because the navigation follows the - onclick - function's
execution.

You could change the onclick attribute to "submitConfirm( );return
false;" and cancel the navigation, but you would be better off using the
FORM element's onsubmit handler.
All works fine in Mozilla and IE,
Consider yourself luck that it does because that is not the behaviour
that you code is strictly asking for.
but Konqueror doesn't behave as
expected.
Instead of submitting the form, the anchor (in this case,
'http://my.site/BrokenSurvey.ht ml#') is loaded instead.
But it is doing what you are asking for in this case. i.e. it submits
the form (an asynchronous process that takes some time) and then it is
navigating to follow the HREF, cancelling the pending submission as it
is no longer interested in displaying the returned response.
I tried it using getElementsByNa me, but with the same result.
I can see no relevance in this.
Am I doing something wrong, or is it time to file a bug
report with the KDE folks?


There is no point in bothering the KDE folks with this, including a
submit button and using the - onsubmit - handler will produce
cross-browser results and consistent behaviour.

Richard.
Jul 23 '05 #2
Richard Cornford wrote:
Greg T wrote:
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 hitting of the enter key was to simply
not have a submit button, instead going for a regular
anchor which calls a javascript confirmation box and then
submits the form.

You figured wrong. There is one obvious, simple and universally
supported (subject of JS availability) palace to intercept the
submission of any form and that is the - onsubmit - handler of the FORM
element.

With its use you can have the submit button that you should have (thus
avoiding any JS dependency in this aspect of the system, and
inconsistencies in the handling of your approach).

<form name="surveyFor m" action=" ... " method="post"
onsubmit="retur n confirm('Are you ready to submit this form?');">
<a href="#" onclick="submit Confirm()"><img
src="submitBt n.png" alt="Submit"></a>

When an - onclick - handler does not return boolean false it is not
cancelling the navigation specified in the HREF. It is normal for
browsers to assume that the last interaction with a page in terms of
form submitting or navigation represents the user's current desire. So
navigating to the specified HREF should be the expected result of this
operation because the navigation follows the - onclick - function's
execution.

You could change the onclick attribute to "submitConfirm( );return
false;" and cancel the navigation, but you would be better off using the
FORM element's onsubmit handler.

....

Thanks for your help, Richard. I was hoping it wouldn't come to the
onsubmit handler. I was looking for a way that would fail if javascript
was disabled, rather than submit the form without prompting.

Looks like your way is good, if I chuck in some detection code.

thanks again,

Greg
Jul 23 '05 #3

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

Similar topics

13
2061
by: Ian Hickson | last post by:
A group of us have been unofficially working on a proposal of extensions to HTML4's Forms chapter, and would like to get input from a wider range of people now that we think our draft proposal is reaching a stable stage: http://www.whatwg.org/specs/web-forms/2004-06-27-call-for-comments/ Some of the features we are proposing include new input control types for dates, times, e-mail addresses, and numbers; a new client-side validation...
10
2109
by: Rob Fentress | last post by:
I am trying to develop very standards-compliant content using XHTML and CSS. I am using CSS positioning and thus need to only include my stylesheet on browsers I have tested to make sure they display correctly. The page is readable without the CSS though the formatting is not pretty, but browsers like Netscape 4.x bungle the positioning if I include the stylesheet, making it unreadable. I am using the JavaScript Browser Sniffer by Eric...
5
1911
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 ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =---
1
1668
by: Richard Dixson | last post by:
I have code that calls document.myFormName.submit() to submit a form automatically via JavaScript. This works just fine. However, if there is a button (or other form field element) on the form named "submit", this results in a JS error saying that "the object doesn't support this property or method". I think what is happening in this case is that document.myFormName.submit() is then trying to call a method on the form field element...
2
1457
by: Phillip Parr | last post by:
Hello, Recently submitting forms (specifically forms which have javascript attached to them with the submit function) has become very slow. The browser appears to sit there for seveal seconds doing nothing (the page also becomes non responsive) and then suddely loads quickly. This happens on all of my computers... What's happened to javascript? Is there some setting that's been turned on that I'm missing?
7
2734
by: Wilhelm Kutting | last post by:
Hi, is there a possibility to use the RETURN for submitting Formdata instead of pushing the Buttton?
5
1570
by: Phlip | last post by:
Engineers: Steps to reproduce the issue: - whip out your Konqueror 3.4.2 - (via Linux 2.6.12-12mdk-i586-up-1GB) - write HTML with an IFrame - src='javascript:void(alert("yo"))' - hit the page
18
13142
by: NavinM | last post by:
I have a couple of forms that are misbehaving in FireFox, but work fine in IE. when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the submission if there is an error. Sample (obviously not working code): <html> <head> <script type="text/javascript"> function Submit() {
3
1370
by: erobinso | last post by:
I have a page that makes use of a tiny/hidden IFRAME that becomes triggered to load HTML into a SPAN element (via .innerHTML). The SPAN expands to display a form that then needs to be validated with javascript residing in the main window before submitting. I use an onclick from a button below the form to start the validation and submission. The page works fine in IE, but in FireFox I just can't get it to submit - the FireBug debugger states:...
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.