473,785 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

blonde question...

I need to do a if statement on only textfields that have a number in them
other then zero. What is the best way to filter out all field values other
then numbers other then zero? I haven't had any luck, I know this should be
a simple thing, but I'm having a blonde day.
Jul 23 '05 #1
12 1347
Terry Olson wrote:
I need to do a if statement on only textfields that have a number in
them other then zero. What is the best way to filter out all field
values other then numbers other then zero? I haven't had any luck, I
know this should be a simple thing, but I'm having a blonde day.


Paint your hair :-D

Get all textfields, check if they have a number, and check if it's zero or
not.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 23 '05 #2
Thank you for turning my question into a statement, and completely avoiding
answering it. Anyone out there want to give me SPECIFICS?

"John Bokma" <po********@cas tleamber.com> wrote in message
news:Xn******** *************** **@130.133.1.4. ..
Terry Olson wrote:
I need to do a if statement on only textfields that have a number in
them other then zero. What is the best way to filter out all field
values other then numbers other then zero? I haven't had any luck, I
know this should be a simple thing, but I'm having a blonde day.


Paint your hair :-D

Get all textfields, check if they have a number, and check if it's zero or
not.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

Jul 23 '05 #3
Terry Olson wrote:

Don't top post
"John Bokma" <po********@cas tleamber.com> wrote in message
Get all textfields, check if they have a number, and check if it's
zero or not.

Thank you for turning my question into a statement, and completely
avoiding answering it. Anyone out there want to give me SPECIFICS?


You asked how, my answer is one way. But you probably want a complete
spelled out solution?

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 23 '05 #4
On Mon, 11 Oct 2004 19:42:30 GMT, Terry Olson <tw******@hotma il.com> wrote:
I need to do a if statement on only textfields that have a number in
them other then zero. What is the best way to filter out all field
values other then numbers other then zero? I haven't had any luck, I
know this should be a simple thing, but I'm having a blonde day.


It would be simple if you were more specific.

When are you checking the text fields? Are you checking *every* text
input, or just a subset?

When these fields contain numbers, should they only contain numbers, and
what do you mean by "filter out"?

About the only thing I can say with certainty is that your answer lies
with regular expressions.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5

Michael Winter wrote:
On Mon, 11 Oct 2004 19:42:30 GMT, Terry Olson <tw******@hotma il.com> wrote:
I need to do a if statement on only textfields that have a number in
them other then zero. What is the best way to filter out all field
values other then numbers other then zero? I haven't had any luck, I
know this should be a simple thing, but I'm having a blonde day.


It would be simple if you were more specific.

When are you checking the text fields? Are you checking *every* text
input, or just a subset?

When these fields contain numbers, should they only contain numbers,
and what do you mean by "filter out"?

About the only thing I can say with certainty is that your answer lies
with regular expressions.

Mike


What about something like this to check every textbox and return every
non-zero value?

<script type="text/javascript">
function checktextboxes( ){
var txtvalue;
var elements = document.getEle mentsByTagName( 'input');
for (var i=0; i<elements.leng th; i++) {
if (elements.item( i).type=="text" ) {
txtvalue = elements.item(i ).value;
if ((parseFloat(tx tvalue)) && (parseFloat(txt value)!=0))
alert(txtvalue) ;
}
}
}
</script>

<input type="text" value="10"><br>
<input type="text" value="5"><br>
<input type="text" value="1"><br>
<input type="text" value="0"><br>
<input type="text" value="-1"><br>
<input type="text" value="-5"><br>
<input type="text" value="-10"><br>
<input type="text" value="asdf"><b r>
<input type="button" value="check textbox values"
onclick="checkt extboxes()">

Mike
Jul 23 '05 #6

"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:opsfq4noa5 x13kvk@atlantis ...
On Mon, 11 Oct 2004 19:42:30 GMT, Terry Olson <tw******@hotma il.com> wrote:
I need to do a if statement on only textfields that have a number in
them other then zero. What is the best way to filter out all field
values other then numbers other then zero? I haven't had any luck, I
know this should be a simple thing, but I'm having a blonde day.
It would be simple if you were more specific.

When are you checking the text fields? Are you checking *every* text
input, or just a subset?


If a group of textfields within a larger group is to be treated differently than
the others, I prefix the name of the field with a couple of meaningful identical
characters, like if the field is "Required", a field name might be
"reqFirstNa me" and the like, then looping through the fields I can address just
those fields to a test, rather than every field. This logic could be employed
here.
When these fields contain numbers, should they only contain numbers, and
what do you mean by "filter out"?

About the only thing I can say with certainty is that your answer lies
with regular expressions.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Jul 23 '05 #7
mscir wrote:
[snip]

What about something like this to check every textbox and return every
non-zero value?

[snip]

Whilst your function neatly cycles through all the text boxes, it
doesn't test very rigorously.

Much more validation is required - your function will return every
value that parseFloat() can turn into a number. e.g. "5ABC" will
return "5" and be accepted by your function as a non-zero number.

The quickest (and dirtiest perhaps...) test I know of is:

if (x == parseFloat(x)) alert(x + ' is a float');

It will accept any number format, including scientific notation. Of
course, it doesn't test the format or suitability of the number for
whatever purpose you want it for (maybe you want an integer).

If you want more rigour or format validation, regular expression tests
are the go.
Cheers, Fred.
Jul 23 '05 #8
Lee
Terry Olson said:

I need to do a if statement on only textfields that have a number in them
other then zero. What is the best way to filter out all field values other
then numbers other then zero? I haven't had any luck, I know this should be
a simple thing, but I'm having a blonde day.


Coding is easier once you've learned to state the problem clearly
and concisely. If you're thinking of the problem as to "filter out
all fields values other than numbers other than zero" you're bound
to be confused.

If you restate it as to "<take some action> on all text fields that
contain numbers that are not zero", it's much simpler:

<html>
<head>
<title>demo</title>
<script type="text/javascript">
function demo(f){
for (var i=0;i<f.element s.length;i++) {
if(f.elements[i].type=="text" &&
!isNaN(f.elemen ts[i].value) &&
0 != +f.elements[i].value) {
// do something with f.elements[i]
alert(f.element s[i].value);
}
}
}
</script>
</head>
<body>
<form>
<input value="">
<input value="3">
<input value="0">
<input value="apple">
<br>
<input type="button" value="test" onclick="demo(t his.form)">
</form>
</body>
</html>

Jul 23 '05 #9
Lee
mscir said:
var elements = document.getEle mentsByTagName( 'input');


I would avoid using getElementsByTa gName(), since there is a much
older mechanism that works just as well, assuming that you're not
interested in accumulating elements from multiple forms.

var elements = thisForm.elemen ts;

Your method will filter out the non-input elements, but you still
have to check the "type" attribute, and the older method will work
in more clients.

Jul 23 '05 #10

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

Similar topics

3
5043
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
2665
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask it differently. FOUR QUESTIONS: The background: I got three (3) files
3
3091
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table before rowID answID qryrow questionID datafield 1591 12 06e 06e 06e question 1593 12 06f 06f 06f question 1594 12 answer to the question 06f
10
3441
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a database or continue to process on to the next page. I am now trying to learn ASP to see if we can replace some of our applications that were written in php with an ASP alternative. However, after doing many searches on google and reading a couple...
10
3738
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server Error in '/QuickStartv20' Application. -------------------------------------------------------------------------------- Configuration Error Description: An error occurred during the processing of a configuration file
17
1976
by: dutchgoldtony | last post by:
Hi, just need a bit of help! I know this is a simple question but it's wrecking my head and I end up just staring at the screen for ages... I have a multi-source program -myProg1.cpp -myProg2.cpp -foo.h All that happens is that myProg1 passes an int to myProg2 which uses the int to dynamically allocate memory for an array using malloc() I've done this before with no problem but not today!!!
53
4095
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.