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

retrieving current input field

Scenario:

I'm using the following code to avoid that users use the return key in the
middle of a form to submit the entire form
---- snip ---------
function kH(e) {
var pK = document.all? window.event.keyCode:e.which;
return pK != 13;
}

document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
---- snip ---------

What I would do is to modify the code so that when the users is in a
textarea input field they are allowed to use the return key. Is there a
funcion/method I can use in the function to test in which named input field
is the active one?
Jul 23 '05 #1
4 1683
Curious. Why aren't you using an onsubmit event? Or are you? I don't
understand why your form is getting submitted when someone presses the
return key. Is this a self processing form?

http://askblax.com
please-answer-here wrote:
Scenario:

I'm using the following code to avoid that users use the return key in the
middle of a form to submit the entire form
---- snip ---------
function kH(e) {
var pK = document.all? window.event.keyCode:e.which;
return pK != 13;
}

document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
---- snip ---------

What I would do is to modify the code so that when the users is in a
textarea input field they are allowed to use the return key. Is there a
funcion/method I can use in the function to test in which named input field
is the active one?


Jul 23 '05 #2
askMe wrote:
Curious. Why aren't you using an onsubmit event? Or are you? I
don't understand why your form is getting submitted when someone
presses the return key. Is this a self processing form?
I don't know neither. The code is inherited. Here is a stripped version:
---[snip]---

<%
response.write("<html><head>")
response.write("<title>Testing</title>")
%>

<script type="text/javascript">
function kH(e) {
var pK = window.event.keyCode;
return pK != 13;
}
document.onkeypress = kH;
</script>

<%
response.write("</head>")
response.write("<body>")
response.write("<form action=""showmodel.asp"" name=""dummy"" >")
response.write("<br><input name=""a"" type=""text"" autocomplete=""off"" >")
response.write("<br><input name=""b"" type=""text"" autocomplete=""off"" >")
response.write("<p><input name=""c"" type=""submit"" >")
response.write("</form>")
response.write("</body>")
response.write("</html>")
%>

Without the onkeypress handler the form gets submitted when i press return
in any of the inupt fields

http://askblax.com
please-answer-here wrote:
Scenario:

I'm using the following code to avoid that users use the return key
in the middle of a form to submit the entire form
---- snip ---------
function kH(e) {
var pK = document.all? window.event.keyCode:e.which;
return pK != 13;
}

document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
---- snip ---------

What I would do is to modify the code so that when the users is in a
textarea input field they are allowed to use the return key. Is
there a funcion/method I can use in the function to test in which
named input field is the active one?

Jul 23 '05 #3
Here I have a simple fix for you,

<script>
function check(cde){
if(cde == 13){
event.returnValue=false
}
}
</script>

<body onkeydown="check(event.keyCode)">

This will do the trick, but remember it will TOTALLY disable the enter
key like previously sugessted maybe try,

<form onsubmit="check(event.keyCode)">

Then you have to submit the form by clicking the submit button.

Hope this helped.

Best Regards,
Sandfordc
http://www.javascript-central.tk

Jul 23 '05 #4
Sandfordc wrote:
Here I have a simple fix for you,

<script>
function check(cde){
if(cde == 13){
event.returnValue=false
}
}
</script>

<body onkeydown="check(event.keyCode)">

This will do the trick, but remember it will TOTALLY disable the enter
key like previously sugessted maybe try,
Hey
Thanks for the advice.
BUT - I'm not having any problems in disabling the return key. Works fine
with my own code. What I would like to implement is that I want to modify
this code, so that when a user is in a textarea they are allowed to use the
return key. So my question is:

can I modify my code or check() above so I can check in which (input) field
the cursor is placed when the key is pressed?

<form onsubmit="check(event.keyCode)">

Then you have to submit the form by clicking the submit button.

Hope this helped.

Best Regards,
Sandfordc
http://www.javascript-central.tk

Jul 23 '05 #5

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

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
7
by: Tony Cooke | last post by:
Hi all. I'm not sure why I'm having problems with this but if I try to retrieve the value of a readonly text form I get back that the object is undefined. The reason the text is readonly is...
8
by: asd | last post by:
I need to find the value/index of the previously selected item of a select list. That is, when the user selects an item from the list and a certain condition elsewhere in the form is not met, I...
2
by: 4Ankit | last post by:
hello all, i am having some difficulty retrieving information from my form. I want to add content in my table but the content i want to add to the table is what the user inputs in my form. ...
6
by: dream2rule | last post by:
<form action='' method='post' name='create_table_form' id='create_table_form' > <table border='0' cellpadding='0' cellspacing='0' width='95%'><tr><td><br /> <table border='0' cellpadding='0'...
4
by: achroiet002 | last post by:
Hi, Please, can someone help me? My problem: I have put a command button onto a form, which retrieves two field values from the current record. With these two values, I am able to open a...
9
ADezii
by: ADezii | last post by:
One question which pops up frequently here at TheScripts is: 'How do I retrieve data from a Recordset once I've created it?' One very efficient, and not that often used approach, is the GetRows()...
3
ADezii
by: ADezii | last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method...
2
by: falroc | last post by:
I have a data base that is used for billing. I have a form called a report selector form. Below is the code used to create the report from the user inputs on the form. What I want to do is add a...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.