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

Use onblur to check whether numeric

170 100+
Hi,

I have a number of text boxes for the user to input either numbers, or letters. Sometimes, the entry must be numeric. So I was thinking of using an onblur thing to check whether the value of the input is numeric, and if not, show an alert box to the user.

I assume I would need to use getelementbyid. And on this page, there might be up to 30 similar input text fields, all of which need to be checked when the focus is lost. But obviously, they would have different ids, and I don't want to have to have 30 different javascript functions to check. Is there a way around this?

To summarise, as the user enters something into the text field, when they click somewhere else, I need to check that entry to see if it's numeric, and I need to do it for as many text fields as there are on the page.

I am not remotely a javascript expert.
Apr 26 '09 #1
3 7051
gits
5,390 Expert Mod 4TB
just make use of the this keyword here that refers to the node itself:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function validateNumericValues(node) {
  5.     alert(node.value);
  6. }
  7. </script>
  8. <body>
  9.     <input type="text" id="foo" onblur="validateNumericValues(this);"/>
  10. </body>
  11. </html>
kind regards
Apr 26 '09 #2
beary
170 100+
Brilliant. Thanks gits. So easy!
Apr 27 '09 #3
gits
5,390 Expert Mod 4TB
:) no problem ... that's what we're here for ;) ...

kind regards
Apr 27 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eric | last post by:
Hello, I'm having trouble with a bit of code that is both validating and updating fields on the fly. Here's something similar to my code: ----------- <script> function validate(field) { var...
6
by: WindAndWaves | last post by:
Hi Gurus In my quest in putting my first javascript together, I am now trying to conquer something that seems trivial, but has taken me hours. I would like to format a field in a form once the...
5
by: EviL KerneL | last post by:
Hi - I cannot seem to get these two events to work together. If I change them to say onmousedown and onmouseup, they seem to work fine. In this case, the onclick appears to work properly but...
3
by: Robert Oschler | last post by:
I have a textarea element that I have created an onblur() handler for. In the onblur() handler, I check to make sure that they have saved the contents of the edit box, before leaving it. If...
2
by: Heiko Vainsalu | last post by:
Hi Hope somebody knows how to solve this one. *The Situation* A traditional situation where HTML form inputs are checked... (if simplified then it would look something like this) <form...
10
by: John Kotuby | last post by:
Hello all... I am working on an ASP.NET 2.0 application with VS2005 and VB. I have chosen to use popup windows in some cases because it makes the user experience better (according to all the users...
3
by: George Eapen | last post by:
Hi all, i want to check whether a value entered into a specific html field is numeric as well as should contain one decimal value.( eg.23 is not accepted..It should be 23.0) i have come up with...
7
by: laredotornado | last post by:
Hi, Using the onblur handler in a text field, how can I check if the value was changed from what was originally there prior to the user focussing on the text field? Thanks, - Dave
1
by: Duncan | last post by:
Hi all, I'm tearing my hair out on this! I have a simple ASP.NET 2 page with a TextBox control, in the PreRender I set ClientSide events:- Response.Attributes.Add("onchange",...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
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...
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,...

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.