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

button in form

P: n/a
I have the following code in a form:

<input type="button" value="Search for this City"
onClick="CreateDate()">

If I click the button is runs the javascript correctly but if I press
enter it doesn't run correctly. Is there something I can put in the
form so if the user presses return or clicks the button that it runs
the javascript CreateDate() ?

Thanks,
Pete
Jan 18 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Peter said the following on 1/18/2008 4:59 AM:
I have the following code in a form:

<input type="button" value="Search for this City"
onClick="CreateDate()">

If I click the button is runs the javascript correctly but if I press
enter it doesn't run correctly.
That is because you didn't click it. And that is what onclick is, when
you click it.
Is there something I can put in the form so if the user presses
return or clicks the button that it runs the javascript CreateDate() ?
If the button has focus, IE fires the onclick if I press the Enter key.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 18 '08 #2

P: n/a
I've been searching the NET for how I need to give the OnClick focus
but everything refers to javascript and the forms outside js. Its
weird I'm not sure what its executing when I press Enter. It opens a
new window and it runs part of the commands in my js then gives an
error because it needs more info which is executed when the button is
clicked on. If it was me I'd just click the button but I can't
control the end user pressing the Enter key then complaining.

Pete
Jan 18 '08 #3

P: n/a
Randy Webb wrote:
>Is there something I can put in the form so if the user presses return
or clicks the button that it runs the javascript CreateDate() ?

If the button has focus, IE fires the onclick if I press the Enter key.
I had the opposite problem. When I clicked in an input field in my form,
most browsers set the first button in the form to be the default action,
and it gets submitted along with the rest of the form when you press Enter.
Since the first button in my form is a "Delete" button I didn't want it
getting submitted by default.

The answer in this case was to add an invisible button as the first one
in my form, and have my CGI script ignore it.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Jan 18 '08 #4

P: n/a
Steve Swift said the following on 1/18/2008 7:14 AM:
Randy Webb wrote:
>>Is there something I can put in the form so if the user presses
return or clicks the button that it runs the javascript CreateDate() ?

If the button has focus, IE fires the onclick if I press the Enter key.

I had the opposite problem. When I clicked in an input field in my form,
most browsers set the first button in the form to be the default action,
and it gets submitted along with the rest of the form when you press Enter.
Since the first button in my form is a "Delete" button I didn't want it
getting submitted by default.
With a <buttonor <input type="button"The simplest solution for
<button(as idiotic as it sounds) is to make it <button type="button">.
The Enter key is notorious for submitting a form :)
The answer in this case was to add an invisible button as the first one
in my form, and have my CGI script ignore it.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 18 '08 #5

P: n/a
I'm really curious with this problem you met. Would you show more
scripts including HTML & JavaScript or the link of these? Then, we
can see what was going.

from http://njoscript.blogspot.com/
Jan 19 '08 #6

P: n/a
Anjoe13 said the following on 1/19/2008 5:15 AM:
I'm really curious with this problem you met.
What problem? This isn't Google Groups, it is Usenet. Quote what you are
replying to so it is easier to know what you are talking about.
Would you show more scripts including HTML & JavaScript or the link of these?
Then, we can see what was going.
from http://njoscript.blogspot.com/
Not sure I would trust a site that can't fix the script errors on its
own page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 19 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.