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

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.surveyForm.submit();
}
....
}

<a href="#" onclick="submitConfirm()"><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.html#') is loaded instead.

I tried it using getElementsByName, 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 2195
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="surveyForm" action=" ... " method="post"
onsubmit="return 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.surveyForm.submit();
}
...
}
Would have been simpler as:-

function submitConfirm(){
if(confirm("Are you ready to submit this form?")){
document.surveyForm.submit();
}
}
<a href="#" onclick="submitConfirm()"><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.html#') 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 getElementsByName, 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="surveyForm" action=" ... " method="post"
onsubmit="return confirm('Are you ready to submit this form?');">
<a href="#" onclick="submitConfirm()"><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.

....

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
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...
10
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...
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 ----==...
1
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...
2
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...
7
by: Wilhelm Kutting | last post by:
Hi, is there a possibility to use the RETURN for submitting Formdata instead of pushing the Buttton?
5
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...
18
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...
3
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...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.