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

button in form

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

Similar topics

5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action...
15
by: JR | last post by:
Hi. I hope someone out there who is more versed with JavaScript than I can help me with the following annoying problem. Here's the problem. I have a form with the following layout: Column A...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
9
by: Melissa | last post by:
What is the code to delete a command button from a form? Can the code be run from the click event of the button to be deleted? Thanks! Melissa
7
by: Miguel Dias Moura | last post by:
Hello, I am working in ASP.net / VB with Access Database. i have a Multipage in my web site with the Submit button as the last button. When the Submit button is pressed i want the form...
29
by: Tom wilson | last post by:
I can't believe this is such an impossibility... I have an asp.net page. It accepts data through on form fields and includes a submit button. The page loads up and you fill out some stuff. ...
18
by: Colin McGuire | last post by:
Hi - this was posted last weekend and unfortunately not resolved. The solutions that were posted almost worked but after another 5 days of working on the code everynight, I am not further ahead....
5
by: Wonder | last post by:
How can I create or use the msgobx to show a message without a default button. The user has explicity to click on the button, so the msgbox closes it. Thanks,
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
I placed a button on a form menustrip for the purpose of causing the horizontal scrollbar of my form to appear so that I can access controls outside of the form's current view (the controls are...
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
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
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.