473,386 Members | 1,752 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,386 software developers and data experts.

Pressing the <enter> key & javascript

Hi everyone,
I'm a newbie to vb.net. 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
1 2315
By default it submit the form. You should return false to cancel this event.
See :
http://www.cambiaresearch.com/c4/789...avascript.aspx

(as a side note you could perhaps use keypress at least for arrows so that
the user can keep moving by keeping the key pressed ?)
<al*****@altavista.coma écrit dans le message de news:
11*********************@e65g2000hsc.googlegroups.c om...
Hi everyone,
I'm a newbie to vb.net. 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 #2

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...
4
by: bh | last post by:
So, I am debating with someone about this. He believe that you can set up so when the user presses Enter it acts just like Tab, so it follows the tab order between text boxes in .NET just like you...
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: peshrad | last post by:
Hi ! I'm working with Win 2K and Visual Studio 2003. I have a problem because pressing <ENTER> in a text input control causes a postback of my web form. Here comes some example code (already...
4
by: almurph | last post by:
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
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,...
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.