473,669 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run function from form text input on Enter

I have a form that looks something like the following:

<form">
<div id="pg0">
<!-- more HTML here -->
<input type="text" name="f0_0" >
</div>

<div id="pg1" style="display: none;">
<!-- more HTML here -->
</div>

<div id="pg2" style="display: none;">
<!-- more HTML here -->
<input type="submit" name="finish" value="Finish">
</div>
</form>

The form has 3 pages. You fill in details on each page and click a
'continue' button to go to (reveal) the next page. It all works fine
except that when focus is in the text input "f0_0" and the user presses
the Enter key I want to update the information on the current page.

Currently its causing the form to be submitted.

How can I override this behaviour so that the Enter key does not submit
the form when the text input has focus but instead runs one of my functions?

Andrew Poulos
Jun 27 '08 #1
4 2225
Andrew Poulos wrote on 23 jun 2008 in comp.lang.javas cript:
I have a form that looks something like the following:

<form">
<div id="pg0">
<!-- more HTML here -->
<input type="text" name="f0_0" >
</div>

<div id="pg1" style="display: none;">
<!-- more HTML here -->
</div>

<div id="pg2" style="display: none;">
<!-- more HTML here -->
<input type="submit" name="finish" value="Finish">
</div>
</form>

The form has 3 pages. You fill in details on each page and click a
'continue' button to go to (reveal) the next page. It all works fine
except that when focus is in the text input "f0_0" and the user
presses the Enter key I want to update the information on the current
page.

Currently its causing the form to be submitted.

How can I override this behaviour so that the Enter key does not
submit the form when the text input has focus but instead runs one of
my functions?

Andrew Poulos

var ready = false;
.....
<function onsubmit='if (!ready) OneOfYourFuncti ons(); return ready;'
............
<input type="submit" name="finish" value="Finish"
onclick='ready= true;'>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #2
SAM
Evertjan. a écrit :
Andrew Poulos wrote on 23 jun 2008 in comp.lang.javas cript:
>I have a form that looks something like the following:

<form">
<div id="pg0">
<!-- more HTML here -->
<input type="text" name="f0_0" >
</div>

<div id="pg1" style="display: none;">
<!-- more HTML here -->
</div>

<div id="pg2" style="display: none;">
<!-- more HTML here -->
<input type="submit" name="finish" value="Finish">
</div>
</form>

The form has 3 pages. You fill in details on each page and click a
'continue' button to go to (reveal) the next page. It all works fine
except that when focus is in the text input "f0_0" and the user
presses the Enter key I want to update the information on the current
page.

Currently its causing the form to be submitted.

How can I override this behaviour so that the Enter key does not
submit the form when the text input has focus but instead runs one of
my functions?

Andrew Poulos


var ready = false;
....
<function onsubmit='if (!ready) OneOfYourFuncti ons(); return ready;'

Probably :

<form onsubmit='if (!ready) OneOfYourFuncti ons(); return ready;'

...........
<input type="submit" name="finish" value="Finish"
onclick='ready= true;'>

--
sm
Jun 27 '08 #3
SAM wrote on 23 jun 2008 in comp.lang.javas cript:
Evertjan. a écrit :
>Andrew Poulos wrote on 23 jun 2008 in comp.lang.javas cript:
>>I have a form that looks something like the following:

<form">
<div id="pg0">
<!-- more HTML here -->
<input type="text" name="f0_0" >
</div>

<div id="pg1" style="display: none;">
<!-- more HTML here -->
</div>

<div id="pg2" style="display: none;">
<!-- more HTML here -->
<input type="submit" name="finish" value="Finish">
</div>
</form>

The form has 3 pages. You fill in details on each page and click a
'continue' button to go to (reveal) the next page. It all works fine
except that when focus is in the text input "f0_0" and the user
presses the Enter key I want to update the information on the current
page.

Currently its causing the form to be submitted.

How can I override this behaviour so that the Enter key does not
submit the form when the text input has focus but instead runs one of
my functions?

Andrew Poulos


var ready = false;
....
<function onsubmit='if (!ready) OneOfYourFuncti ons(); return ready;'


Probably :

<form onsubmit='if (!ready) OneOfYourFuncti ons(); return ready;'
So true !!!!!
>...........
<input type="submit" name="finish" value="Finish"
onclick='ready =true;'>



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #4
Andrew Poulos wrote:
I have a form that looks something like the following:

<form">
<div id="pg0">
<!-- more HTML here -->
<input type="text" name="f0_0" >
</div>

<div id="pg1" style="display: none;">
<!-- more HTML here -->
</div>

<div id="pg2" style="display: none;">
<!-- more HTML here -->
<input type="submit" name="finish" value="Finish">
</div>
</form>

The form has 3 pages. You fill in details on each page and click a
'continue' button to go to (reveal) the next page. It all works fine
except that when focus is in the text input "f0_0" and the user presses
the Enter key I want to update the information on the current page.

Currently its causing the form to be submitted.

How can I override this behaviour so that the Enter key does not submit
the form when the text input has focus but instead runs one of my functions?
Start with Valid HTML. Then try this quickhack:

<script type="text/javascript">
function submitCheck(f)
{
var me = arguments.calle e;
if (typeof me.event != "undefined" )
{
var e = me.event;
var t = e.target || e.srcElement;
if (t && typeof t.name != "undefined"
&& /(^|\s)foo(\s|$)/i.test(t.name))
{
return false;
}
}

return true;
}
</script>

<form action="..."
onkeydown="if (typeof event != 'undefined') submitCheck.eve nt = event"
onsubmit="retur n submitCheck(thi s)">
...
<input type="..." name="foo" ...>
...
<input type="submit" ... onclick="delete submitCheck.eve nt">
...
</form>

I think I have posted a similar solution before here.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #5

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

Similar topics

4
4440
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most part, the scripts were created with http://phpcodegenie.sourceforge.net/
3
3549
by: KathyB | last post by:
Hi, I've tried everything I can think of. Using the script below, I thought on submit my ConfirmSave function would run, then if true returned, would run my form action. At this point it appears to be skipping the function altogether. I'm also unable to get the textbox.value since I need to use variable for the form name and input element name. I'm fairly new to this...please tell me where I am going astray...Thanks. HTML element:
15
6566
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and the buttons. The problem is when I post a form to itself, the Enter key will not submit the form, it only clears the contents of the text box. The only way I can submit is to click the submit button. Here is a simplified version of my code that I...
12
6995
by: Susan Cranford | last post by:
Please forgive, I have looked at so much info I can't figure out how to put it together even though I know it must be fairly simple. I have an array of input text boxes (txtDOBn) where n is created at load. On the onchange event I want to calc the age and show in adjacent input text boxes that are readonly and also arrays (an age calced for each DOB entered). I was going to use the datediff function in vbscript to do the calc. Can...
4
2142
by: Matt | last post by:
I have the following in a page and I am trying to update a record on the next page but for some reason the form data is not carrying over. Any ideas why? <form name=nxtlupdate method=post action=supers_NxtlUpdate.asp> <% Do While Not objRecordset.EOF
5
2541
by: eyoung | last post by:
I have a function to check a string to make sure it is 6 digites using the trigger onBlur="CkFrmt(this)" Problem is I've got 4 fields in a row...if I enter a wrong number in the first and hit tab I get the error message and my script tries to move the focus to the first item...but because I hit the tab the focus in already on the second item which does not contain a 6 digit value so I must kill the page. help! function CkFrmt(str) {
6
4928
by: Paul Furman | last post by:
I'm getting incorrect response when hitting the enter key instead of actually clicking the button on a form. It activates but the post data isn't being sent I think. The php generated page flickers & reloads but doesn't perform the update. This is php generated, I'm just pasting the page source (reformatted & extra junk removed and I think they are now identical), and it's running on my localhost apache server for testing so maybe...
3
2972
by: Adrock952 | last post by:
I have been trying for ages to work out how to highlight a form field using css when there is an error during validation. I have got the form to validate fine but i don't know how to change the background-color of the form element in question. I would like for example, if the user has forgotten to enter their email address, the field is highlighted so they know what they have to enter. Any valid fields are left the same color. here is...
4
1353
by: jshokoo | last post by:
can someone help me with the code below .there is no call to the checkForm function.I have just included the part to validate the name text area platform: rational v6 os : xppro language: javascript source code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD>
0
8382
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
8893
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
8802
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
8586
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
8658
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...
1
6209
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
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.