473,387 Members | 3,750 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,387 software developers and data experts.

Detecting <enter> key-press not working - please help

Hi everyone,
I'm a newbie to javascript. I have written some code to detect when a
user presses the down-arrow, up-arrow and enter button. Essentially
the user can arrow down or up through a list and the textbox is
populated with the option when the user presses the enter button. This
is for a VB.NET Web form type project.

The problem is that when I press the enter button the entire form get
refreshed and the javascript code is not executed. Or perhaps it is
but get "over-ruled" if you take my meaning.

Any comments/suggestions much appraciated. I have included the HTML
et al code below:

Cheers,
Al
****CODE*****
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script type="text/javascript">
function Test()
{

var retVal =
WebForm1.GetUsernameList(document.Form1.txtName.va lue);
//Populate the innerHTML of the div with the results

javascript:document.getElementById('nameList').sty le.display = "";
document.getElementById('nameList').innerHTML = retVal.value;

//alert(retVal.value)
}
</script>
<script type="text/javascript">
var count = 1

function previousSuggestion(){

var Nodes = document.getElementById ('colm')
var items = Nodes.getElementsByTagName('td')

items(count).style.backgroundColor = "#EFEFEF";

}//end previousSuggestion

function nextSuggestion(count){

var Nodes = document.getElementById ('colm')
var items = Nodes.getElementsByTagName('td')

items(count).style.backgroundColor = "#EFEFEF";

}//end nextSuggestion

function chooseSuggestion(){

document.getElementById ('txtName').innerText =
items(count).innerText

}//end chooseSuggestions

function keyHandler() {
switch (event.keyCode) {
case 38: //up-arrow
this.previousSuggestion()
if (count == 1)
count = count
else
count--
break
case 40: //down-arrow
this.nextSuggestion(count)
count++
break
case 13: //enter=13, tab=9
this.chooseSuggestion()
}
}
</script>
</HEAD>
<body ms_positioning="GridLayout" >
<form id="Form1" method="post" runat="server" onkeyup="javascript:
keyHandler()">
&nbsp; <INPUT id="txtName" onkeyup="javascript: Test()"
type="text">
<DIV id="nameList">&nbsp;</DIV>
</form>
</TEXTAREA></body>
</HTML>

Mar 14 '07 #1
4 4825
Try amending the keyHandler() function as below, so the section
relating to the enter key returns false. Returning false from a
keypress should stop any of the other default events associated with
that keypress.

function keyHandler() {
switch (event.keyCode) {
case 38: //up-arrow
this.previousSuggestion();
if (count == 1)
count = count;
else
count--;
break;
case 40: //down-arrow
this.nextSuggestion(count);
count++;
break;
case 13: //enter=13, tab=9
this.chooseSuggestion();
return false;
}
}
Mar 14 '07 #2
On Mar 14, 4:36 pm, "wisestpotato" <wisestpot...@googlemail.com>
wrote:
Try amending the keyHandler() function as below, so the section
relating to the enter key returns false. Returning false from a
keypress should stop any of the other default events associated with
that keypress.

function keyHandler() {
switch (event.keyCode) {
case 38: //up-arrow
this.previousSuggestion();
if (count == 1)
count = count;
else
count--;
break;
case 40: //down-arrow
this.nextSuggestion(count);
count++;
break;
case 13: //enter=13, tab=9
this.chooseSuggestion();
return false;
}

}- Hide quoted text -

- Show quoted text -
No joy wisepotato - I've tried it in both debug and release mode but
its not working. It does not throw and error but does not populate the
field. Bummer...

Mar 14 '07 #3
ASM
al*****@altavista.com a écrit :
>
Any comments/suggestions much appraciated. I have included the HTML
et al code below:
(snip)
function previousSuggestion(){
>
var Nodes = document.getElementById ('colm')
var items = Nodes.getElementsByTagName('td')

items(count).style.backgroundColor = "#EFEFEF";
items[count].style.backgroundColor = "#EFEFEF";
}//end previousSuggestion

function nextSuggestion(count){

var Nodes = document.getElementById ('colm')
var items = Nodes.getElementsByTagName('td')

items(count).style.backgroundColor = "#EFEFEF";
items[count].style.backgroundColor = "#EFEFEF";
}//end nextSuggestion

function chooseSuggestion(){

document.getElementById ('txtName').innerText =
items(count).innerText
always same error :

items[count] would be OK
>
}//end chooseSuggestions

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Contact : http://stephane.moriaux.perso.wanadoo.fr/contact
ASM = Aimable Stéphane Moriaux = Amateur Sasseur Merdouilles
Mar 14 '07 #4
On Mar 14, 4:51 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
almu...@altavista.com a écrit :
Any comments/suggestions much appraciated. I have included the HTML
et al code below:

(snip)
function previousSuggestion(){
var Nodes = document.getElementById ('colm')
var items = Nodes.getElementsByTagName('td')
items(count).style.backgroundColor = "#EFEFEF";

items[count].style.backgroundColor = "#EFEFEF";
}//end previousSuggestion
function nextSuggestion(count){
var Nodes = document.getElementById ('colm')
var items = Nodes.getElementsByTagName('td')
items(count).style.backgroundColor = "#EFEFEF";

items[count].style.backgroundColor = "#EFEFEF";
}//end nextSuggestion
function chooseSuggestion(){
document.getElementById ('txtName').innerText =
items(count).innerText

always same error :

items[count] would be OK
}//end chooseSuggestions

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Contact :http://stephane.moriaux.perso.wanadoo.fr/contact
ASM = Aimable Stéphane Moriaux = Amateur Sasseur Merdouilles
Thanks Stephen. I've implemented that - nice. Enter button still
clears everything though. I'm thinking now that this may be a VB.NET
"thing" rather than a "javascript" thing...

Mar 14 '07 #5

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

Similar topics

11
by: Denis Hierstein | last post by:
I need a function, witch make a break in a for-loop and wait for the <enter>-key ... when I use Pascal I just use the Read; or the ReadLn;-function, then the loop stop as long as the user push the...
2
by: Brett | last post by:
I have a text area form object. A user clicks a send button and the text area information is submitted. How can I also allow the information to be submitted after the user hits the <enter> key? ...
4
by: aurgathor | last post by:
I have a code that reads in 2 shorts, and checks if they are in a given range. I'd like to modify it to use a predefined default value if nothing, but as newline is entered. What would be the...
7
by: jerrygarciuh | last post by:
Hello, I have been playing with various Googled solutions for capturing the <Enter> key to suppress form submission. My first question is whether anyone has a script that works in all common...
7
by: Susan Bricker | last post by:
I know that I saw some information concerning the <shift>+<enter> combination use to bypass launching an Access mdb application and enter the Access design workspace. Would someone please direct...
6
by: tor | last post by:
Hello How can I use an other key then TAB to move from one textBox to another?? Torfinn
5
by: DotNetGruven | last post by:
Hi, I have a web form which has: - Login area with - email textbox - password textbox - <enter> button to log in - search area with - string to search for textbox
2
by: Rocio | last post by:
I have a aspx page, with 2 controls (ascx). Control1 contains a SEARCH button, and textbox to enter the string to search for. Control 2 contains a LOGIN button, and 2 text boxes to enter the...
4
by: Paul W | last post by:
On my simple login-screen I have a 'username' and 'password' field and an imagebutton for the 'OK'. This used to work nicely so that when the user hit <Enter> from the password field, it invoked...
2
by: jakepillai | last post by:
Hey guys, I am new to Python and I was wondering how to get a program to recognize the <enter> key when a user hits it thnx
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.