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

Javascript beeping an error, but code is working


I recently added a small Javascript routine to one of our simple search
forms. The form has two text input fields, one for a number, the other
for a name, and it has a button labeled "search". The change I added to
this form was that if a user hit enter after completing either field, it
would be just as though the user had pressed the button and the search
would happen.

Without the handler, the user's browser just causes their machine to
beep an error, because, as I'm sure you know, onSubmit doesn't default
to an enter key with more than one text field present.

I added the following to each text field definition:

onKeyPress="check_enter(event)"

the code called is:

function check_enter(e)
{
var char_code;

if(e && e.which) {
e = e;
char_code = e.which;
} else {
e = event;
char_code = e.keyCode;
}
if(char_code == 13)
run_acc_search();
else
return true;
}

This is working completely, but the machine is still issuing the same
error beep when the user presses enter as though an error was made.

What have I got wrong?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
5 1591
John Scalia wrote:
Without the handler, the user's browser just causes their machine to
beep an error, because, as I'm sure you know, onSubmit doesn't default
to an enter key with more than one text field present.
I wonder how you got the idea. If I press Enter/Return, the form is
submitted regardless how many "text fields" are present. Atigs.
I added the following to each text field definition:

onKeyPress="check_enter(event)"
You might want to consider to handle the `submit' event of the form instead.
the code called is:

function check_enter(e)
{
var char_code;

if(e && e.which) {
e = e;
The above line is completely useless.
char_code = e.which;
} else {
e = event;
char_code = e.keyCode;
}
if(char_code == 13)
run_acc_search();
else
return true;
}

This is working completely, but the machine is still issuing the same
error beep when the user presses enter as though an error was made.

What have I got wrong?


You have mixed up your alternatives, and you have not posted the declaration
of run_acc_search(). Try this:

function check_enter(e)
{
if (!e) e = window.event;
if (e)
{
if ((e.which || e.keyCode) == 13)
{
run_acc_search();

/*
* Use this or let run_acc_search() return `false'
* and then return its return value;
*/
return false;
}
}
return true;
}
HTH

PointedEars
--
186,000 miles per second. It's not just a good idea, it's the law!
Jul 23 '05 #2
John Scalia wrote:
Without the handler, the user's browser just causes their machine to
beep an error, because, as I'm sure you know, onSubmit doesn't default
to an enter key with more than one text field present.
I wonder how you got the idea. If I press Enter/Return, the form is
submitted regardless how many "text fields" are present. Atigs.
I added the following to each text field definition:

onKeyPress="check_enter(event)"
You might want to consider to handle the `submit' event of the form instead.
the code called is:

function check_enter(e)
{
var char_code;

if(e && e.which) {
e = e;
The line above is completely useless.
char_code = e.which;
} else {
e = event;
char_code = e.keyCode;
}
if(char_code == 13)
run_acc_search();
else
return true;
}

This is working completely, but the machine is still issuing the same
error beep when the user presses enter as though an error was made.

What have I got wrong?


You have mixed up your alternatives, and you have not posted the declaration
of run_acc_search(). Try this:

function check_enter(e)
{
if (e && (e.which || e.keyCode) == 13)
{
run_acc_search();

/*
* Use this or let run_acc_search() return `false'
* and then return its return value;
*/
return false;
}
return true;
}
HTH

PointedEars
--
186,000 miles per second. It's not just a good idea, it's the law!
Jul 23 '05 #3
John Scalia wrote:
Without the handler, the user's browser just causes their machine to
beep an error, because, as I'm sure you know, onSubmit doesn't default
to an enter key with more than one text field present.
I wonder how you got the idea. If I press Enter/Return, the form is
submitted regardless how many "text fields" are present. Atigs.
I added the following to each text field definition:

onKeyPress="check_enter(event)"
If you are going to use the result of check_enter(), you have to return its
return value to the event handler:

onkeypress="return check_enter(event);"

However, you might want to consider to handle the `submit' event of the form
instead.
the code called is:

function check_enter(e)
{
var char_code;

if(e && e.which) {
e = e;
The line above is completely useless.
char_code = e.which;
} else {
e = event;
char_code = e.keyCode;
}
if(char_code == 13)
run_acc_search();
else
return true;
}

This is working completely, but the machine is still issuing the same
error beep when the user presses enter as though an error was made.

What have I got wrong?


You have mixed up your alternatives, and you have not posted the declaration
of run_acc_search(). Try this:

function check_enter(e)
{
if (e && (e.which || e.keyCode) == 13)
{
run_acc_search();

/*
* Use this or let run_acc_search() return `false'
* and then return its return value;
*/
return false;
}
return true;
}
HTH

PointedEars
--
186,000 miles per second. It's not just a good idea, it's the law!
Jul 23 '05 #4
In a message originally dated November 11, 2004, Thomas 'PointedEars'
Lahn decided to answer on December 12, 2004 and wrote:
John Scalia wrote:

Without the handler, the user's browser just causes their machine to
beep an error, because, as I'm sure you know, onSubmit doesn't default
to an enter key with more than one text field present.

I wonder how you got the idea. If I press Enter/Return, the form is
submitted regardless how many "text fields" are present. Atigs.


He didn't say the form didn't submit, he said the onSubmit doesn't
default to an enter key.

But is this your way of keeping people from correcting you is by
answering posts that are over 30 days old? You seem to be an expert at that.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
JRS: In article <18****************@PointedEars.de>, dated Sun, 12 Dec
2004 09:09:49, seen in news:comp.lang.javascript, Thomas 'PointedEars'
Lahn <Po*********@web.de> posted :

PointedEars
--
186,000 miles per second. It's not just a good idea, it's the law!


You are profoundly ignorant. Throughout the modern world, the
measurement system is by law SI, the International System, and the speed
of light is 299792458 m/s exactly. And 299792458000/25.4/36/1760 =
186282.3970512208701185079137835043346854370476417 7205 ...

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6

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

Similar topics

5
by: Alexander Schmolck | last post by:
This is only partly a python question, but what is the easiest way to get python to (reliably) beep under linux? By reliably I mean that ``print "\b"`` won't do because it depends on the terminal...
6
by: Andy Fish | last post by:
Hi, I want to use an anchor tag to invoke some javascript and I've read that it's bad form to use <a href="javascript:foo()"> I've read endless usenet posts and hint sites on the net, they all...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
3
by: krishna | last post by:
Below is the code. language = asp.net/vb.net private sub openW() sResult = sResult & "<script language=javascript> mywindow =...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
0
by: adrian | last post by:
Hi, I'm using SnmpSendMsg from within VB.net 2005, everything is working fine but occasionally calling SnmpSendMsg causes a system exclamation beep. As I'm querying several values this causes...
9
Subsciber123
by: Subsciber123 | last post by:
I am running a program that I wrote (a compression program {it is not finished yet}), and when I run it, my computer makes a continuous beeping sound (the same sound your computer makes if you press...
1
by: tvnaidu | last post by:
MY PC (windows 2000 prof) keep beeping - if I mute audio also beeping - looklike motherboard beeping. It just started today, earlier no beep at all, suddenly started. any diagnostic tip?....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.