473,325 Members | 2,870 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,325 software developers and data experts.

Safari enter/return bypassing my button script

I have a form and a button to submit it. The button is made from:

<input type=button onclick='myHandler(this.form);'>

This all works fine except that in Safari 2.0.4, the enter/return keys,
if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit='return false;'>

except that if at the time enter/return is pressed, the focus is on one
of the iframes in my form, then the iframe gets reloaded (with goofy
parameters, of course). If the focus is nowhere when enter/return is
pressed, then these get ignored OK.

Note that with Firefox Mac and any WIndows browser, return seems to be
ignored.

How can I prevent Safari from submitting the form when enter/return are
pressed?

Thanks,
Jun 12 '07 #1
10 5495
Tim Streater <ti**********@dante.org.ukwrote in
news:ti********************************@news.indiv idual.net:
I have a form and a button to submit it. The button is made from:

<input type=button onclick='myHandler(this.form);'>

This all works fine except that in Safari 2.0.4, the enter/return
keys, if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit='return false;'>
First off, though this isn't the reason for your problem, you can't expect
javascript to work properly if your (X)HTML markup is bad. Your button
script should be <input type="button" onclick="myHandler(this.form);">
(quotes around the input type).

You will no doubt find javascript behaving oddly if your document isn't
valid.

That aside, why can't you put the myHandler function on the form submit?
Will that solve the Safari problem?

<form onsubmit="return myHandler(this);">
Jun 12 '07 #2
Good Man said the following on 6/12/2007 11:56 AM:
Tim Streater <ti**********@dante.org.ukwrote in
news:ti********************************@news.indiv idual.net:
>I have a form and a button to submit it. The button is made from:

<input type=button onclick='myHandler(this.form);'>

This all works fine except that in Safari 2.0.4, the enter/return
keys, if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit='return false;'>

First off, though this isn't the reason for your problem, you can't expect
javascript to work properly if your (X)HTML markup is bad.
There is nothing "bad" or "invalid" about that HTML. The only time
attributes are *required* to be quoted is if they have a space or other
special characters in them.
Your button script should be <input type="button" onclick="myHandler(this.form);">
(quotes around the input type).
Nonsense. The code posted validates just fine.
You will no doubt find javascript behaving oddly if your document isn't
valid.
Now that is true but it isn't the problem here as it is irrelevant.
That aside, why can't you put the myHandler function on the form submit?
Because the form submit even handler probably doesn't do what is wanted.
The only way that would get fired is to submit the form and that isn't
always desired. It would be pretty insane if myHandler simply set the
value of an input.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 12 '07 #3
In article <Xn************************@216.196.97.131>,
Good Man <he***@letsgo.comwrote:
Tim Streater <ti**********@dante.org.ukwrote in
news:ti********************************@news.indiv idual.net:
I have a form and a button to submit it. The button is made from:

<input type=button onclick='myHandler(this.form);'>

This all works fine except that in Safari 2.0.4, the enter/return
keys, if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit='return false;'>

First off, though this isn't the reason for your problem, you can't expect
javascript to work properly if your (X)HTML markup is bad. Your button
script should be <input type="button" onclick="myHandler(this.form);">
(quotes around the input type).
Are you saying that these:

<form onsubmit='return false;'>
<form onsubmit="return false;">

are not equivalent?
That aside, why can't you put the myHandler function on the form submit?
Will that solve the Safari problem?

<form onsubmit="return myHandler(this);">
I did try this but it didn't work - probably because I didn't do it
properly (left the form.submit in there etc etc). I'll have to do it
more carefully and see how I get on.

I would have preferred my solution if I could have made that disable the
effect of return doing a submit - but anyway.

Funnily enough, from what I read in the JavaScript Bible I was left with
the impression that the return/enter key *should* do a submit - but
Safari seems the only one that does that.

Thanks,
Jun 12 '07 #4
Tim Streater said the following on 6/12/2007 12:26 PM:
In article <Xn************************@216.196.97.131>,
Good Man <he***@letsgo.comwrote:
>Tim Streater <ti**********@dante.org.ukwrote in
news:ti********************************@news.indi vidual.net:
>>I have a form and a button to submit it. The button is made from:

<input type=button onclick='myHandler(this.form);'>

This all works fine except that in Safari 2.0.4, the enter/return
keys, if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit='return false;'>
First off, though this isn't the reason for your problem, you can't expect
javascript to work properly if your (X)HTML markup is bad. Your button
script should be <input type="button" onclick="myHandler(this.form);">
(quotes around the input type).

Are you saying that these:

<form onsubmit='return false;'>
<form onsubmit="return false;">

are not equivalent?
No, he was attempting to say that type=button was invalid HTML, which it
isn't, and that you should have quoted it type="button" which is totally
irrelevant as either is valid HTML.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 12 '07 #5
In article <Tt*********************@telcove.net>,
Randy Webb <Hi************@aol.comwrote:
Good Man said the following on 6/12/2007 11:56 AM:
Tim Streater <ti**********@dante.org.ukwrote in
news:ti********************************@news.indiv idual.net:
I have a form and a button to submit it. The button is made from:

<input type=button onclick='myHandler(this.form);'>

This all works fine except that in Safari 2.0.4, the enter/return
keys, if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit='return false;'>
First off, though this isn't the reason for your problem, you can't expect
javascript to work properly if your (X)HTML markup is bad.

There is nothing "bad" or "invalid" about that HTML. The only time
attributes are *required* to be quoted is if they have a space or other
special characters in them.
Your button script should be <input type="button"
onclick="myHandler(this.form);">
(quotes around the input type).

Nonsense. The code posted validates just fine.
You will no doubt find javascript behaving oddly if your document isn't
valid.

Now that is true but it isn't the problem here as it is irrelevant.
That aside, why can't you put the myHandler function on the form submit?

Because the form submit even handler probably doesn't do what is wanted.
The only way that would get fired is to submit the form and that isn't
always desired. It would be pretty insane if myHandler simply set the
value of an input.
myHandler in fact delves into a number of iframes to pull some values
out and stick them in the form. Hence the disaster of having it
bypassed. You can hit return quite easily if you're aiming for backspace.
Jun 12 '07 #6
Randy Webb <Hi************@aol.comwrote in
news:3d********************@telcove.net:

>Are you saying that these:

<form onsubmit='return false;'>
<form onsubmit="return false;">

are not equivalent?

No, he was attempting to say that type=button was invalid HTML, which
it isn't, and that you should have quoted it type="button" which is
totally irrelevant as either is valid HTML.
Sure, while <input type=button value="dance" /is valid HTML, it is not
valid XHTML, which I should have specified

validator.w3.org/check:

**

This page is not Valid XHTML 1.0 Transitional!

Below are the results of checking this document for XML well-formedness
and validity.

1. Error Line 9 column 12: an attribute value specification must be
an attribute value literal unless SHORTTAG YES is specified.

<input type=button value="dance" />
Jun 12 '07 #7
In article <ti********************************@news.individua l.net>,
Tim Streater <ti**********@dante.org.ukwrote:
I have a form and a button to submit it. The button is made from:

<input type=button onclick='myHandler(this.form);'>

This all works fine except that in Safari 2.0.4, the enter/return keys,
if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit='return false;'>

except that if at the time enter/return is pressed, the focus is on one
of the iframes in my form, then the iframe gets reloaded (with goofy
parameters, of course). If the focus is nowhere when enter/return is
pressed, then these get ignored OK.
I added the <form onsubmit='return false;'also to the <form>s in my
iframes, and now all is well.
Jun 13 '07 #8
Good Man said the following on 6/12/2007 1:20 PM:
Randy Webb <Hi************@aol.comwrote in
news:3d********************@telcove.net:

>>Are you saying that these:

<form onsubmit='return false;'>
<form onsubmit="return false;">

are not equivalent?
No, he was attempting to say that type=button was invalid HTML, which
it isn't, and that you should have quoted it type="button" which is
totally irrelevant as either is valid HTML.

Sure, while <input type=button value="dance" /is valid HTML
Only if you want the consequences, or possible consequences, of the / in
the end of it which gives the browser all rights to display the on the
page.
, it is not valid XHTML, which I should have specified
You specified (X)HTML which implies both. It is valid HTML and anybody
that serves XHTML, on the web, doesn't need a browser, they need a
straight jacket and a competent doctor to treat them.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 13 '07 #9
Randy Webb <Hi************@aol.comwrote in news:Rv-
dn*****************@telcove.net:

You specified (X)HTML which implies both. It is valid HTML and anybody
that serves XHTML, on the web, doesn't need a browser, they need a
straight jacket and a competent doctor to treat them.
Thanks for the opinion, but I won't get sucked into that debate at the
moment.
Jun 13 '07 #10
Good Man said the following on 6/13/2007 1:08 PM:
Randy Webb <Hi************@aol.comwrote in news:Rv-
dn*****************@telcove.net:

>You specified (X)HTML which implies both. It is valid HTML and anybody
that serves XHTML, on the web, doesn't need a browser, they need a
straight jacket and a competent doctor to treat them.

Thanks for the opinion, but I won't get sucked into that debate at the
moment.
Then don't use XHTML as a defense for an incorrect statement :-)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 13 '07 #11

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

Similar topics

2
by: Marcia Gulesian | last post by:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or later (Windows) but not when run in Safari (Mac) <body onkeypress="javascript:keysuppress(event)" > function...
5
by: Girish | last post by:
I have TWO submit buttons of type IMAGE on my asp form. This renders as <input type="image">. I need to be able to eble the ENTER button for both buttons. Yes, I know that for the input type...
4
by: drew197 | last post by:
I am a newbie. I am editing someone elses code to make it compatible with Firefox and Safari. In IE, when you click on the proper link, a block of text is shown in a nice paragraph form. But, in...
7
by: ja | last post by:
Hi, I've made an pseudo-select, wich using DOM functions like: document.createElement() appendChild() document.getElementById() with(obj){
2
by: ipy2006 | last post by:
Only in Safari browser the current year shows as 1970. Also "Non digits found in year" is triggered in the Safari broswer. Please help. Thanks, Yasaswi function verifyYear( field ) { var _x =...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
2
by: Greg Taylor | last post by:
Greetings, I was wondering if there was a way to make prompt() calls in Safari show a single-line input box instead of the default multi-line prompt that it currently does. It seems like most...
5
by: loveshack | last post by:
Can anyone help me please (i am quite a novice, but having fun learning). Im not sure if this is an ASP problem, a javascript problem or a browser problem. Firstly, everything i have written...
5
by: Jason | last post by:
Hi all, Are you familiar with Safari? I have a site that works perfectly in IE6 IE7 FF2 FF3 but not in the latest Safari. When I test xsltProcessor, there is a error as following, I have dealt...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.