473,386 Members | 1,720 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.

isNum

I have been trying to get this code to work and the isNum seem to be giving
me a problem and I just cannot figure it out any help would me very much
appreciated!!

Thanks in advance!!!

function SubmitSame() {
var usernew, QPSQTY, PTPS, PSSQTY, PSST, ECQTY, ECT, EXQTY, EXT, INQTY,
INTA, SKQTY, SKT, CSQTY, CST, total, result, result1, result2, result3,
result4, result5, result6, result0;
if (document.getElementById) {
usernew = document.getElementById('usernew');
QPSQTY = document.getElementById('QPSQTY');
PTPS = document.getElementById('PTPS');
PSSQTY = document.getElementById('PSSQTY');
PSST = document.getElementById('PSST');
ECQTY = document.getElementById('ECQTY');
ECT = document.getElementById('ECT');
EXQTY = document.getElementById('EXQTY');
EXT = document.getElementById('EXT');
INQTY = document.getElementById('INQTY');
INTA = document.getElementById('INTA');
SKQTY = document.getElementById('SKQTY');
SKT = document.getElementById('SKT');
CSQTY = document.getElementById('CSQTY')
CST = document.getElementById('CST');
total = document.getElementById('total');
}
else {
usernew = document.usernew;
QPSQTY = usernew.QPSQTY;
PTPS = usernew.PTPS;
PSSQTY = usernew.PSSQTY;
PSST = usernew.PSST;
ECQTY = usernew.ECQTY;
ECT = usernew.ECT;
EXQTY = usernew.EXQTY;
EXT = usernew.EXT;
INQTY = usernew.INQTY;
INTA = usernew.INTA;
SKQTY = usernew.SKQTY;
SKT = usernew.SKT;
CSQTY = usernew.CSQTY;
CST = usernew.CST;
total = usernew.total;
}
if (!isNum(QPSQTY.value)) {
return ; }
}

Jul 23 '05 #1
6 18544
Rick wrote:
I have been trying to get this code to work and the isNum seem to be giving
me a problem and I just cannot figure it out any help would me very much
appreciated!!
[...] }
if (!isNum(QPSQTY.value)) {
return ; }
}


I think you are confused with isNaN(), which returns true if the
argument is not a number.

isNaN(QPSQTY.value)

will return true if the text entered into QPSQTY is not a
number. Here, play with this:

<input type="text" value="6" onblur="
document.getElementById('xx').innerHTML =
this.value + ' isNaN? : ' + isNaN(this.value);
">
<span id="xx"></span>
e.g. 23e345 *is* a valid number and will return false.
.23 is a valid number and will return false.
123qwe is not a valid number and will return true.

--
Fred
Jul 23 '05 #2
Wow that worked perfect.

What is the isNum for?

Thanks you very much!!!
"Fred Oz" <Oz****@iinet.net.auau> wrote in message
news:KD****************@news.optus.net.au...
Rick wrote:
I have been trying to get this code to work and the isNum seem to be
giving
me a problem and I just cannot figure it out any help would me very much
appreciated!!

[...]
}
if (!isNum(QPSQTY.value)) {
return ; }
}


I think you are confused with isNaN(), which returns true if the
argument is not a number.

isNaN(QPSQTY.value)

will return true if the text entered into QPSQTY is not a
number. Here, play with this:

<input type="text" value="6" onblur="
document.getElementById('xx').innerHTML =
this.value + ' isNaN? : ' + isNaN(this.value);
">
<span id="xx"></span>
e.g. 23e345 *is* a valid number and will return false.
.23 is a valid number and will return false.
123qwe is not a valid number and will return true.

--
Fred

Jul 23 '05 #3
Rick wrote:
Wow that worked perfect.

What is the isNum for?
Nothing.

Thanks you very much!!!


You're welcome.

[...]
As a tip, here is a better way of doing what you are doing. It
does two things:

Puts your variables into objects, one for text one for numbers,
and uses the forms collection to avoid using getElementById.

You could include the DynWrite[1] function to provide
getElementById for those browsers that support document.all, but
I think the forms collection is simpler (assuming that you are
using a form...)

The function I've written just changes the style of a form
element depending on whether isNaN returns true or false, hardly
an exhaustive test of whether the input really is a number but
illustrative anyway.

I could have done the isNaN test when reading the values, but
that wouldn't show getting the values back from the object.

1. <URL:http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>Mod Style Play</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
..isText {font-weight: normal; color: blue;}
..isNumber {font-weight: bold; color: red;}
</style>
<script type="text/JavaScript">

function SubmitSame(theForm) {
// Just a guess, but are these the names
// of inputs in a form? If so, put them in an array

// all the text elements (just guessing)
var txtIn = {
'usernew':'','QPSQTY':'','PTPS':'','PSSQTY':'','PS ST':'',
'ECQTY':'','ECT':'','EXQTY':''
};
// all the number elements (just guessing)
var numIn = {
'EXT':'','INQTY':'','INTA':'','SKQTY':'','SKT':'',
'CSQTY':'','CST':'','total':''
};
var result, result1, result2, result3,
result4, result5, result6, result0, t, n;

// Now just loop through the elements of the objects and use
// the forms collection - no getElementById/all issues
for ( t in txtIn) {
txtIn[t] = theForm.elements[t].value;
}
for ( n in txtIn) {
txtIn[n] = theForm.elements[n].value;
}

// Test to see if isNaN & modify class accordingly
// Demonstrates looping through elements of an object
for (t in txtIn) {
theForm.elements[t].className =
(isNaN(txtIn[t]))? 'isText':'isNumber';
}
for (n in numIn) {
theForm.elements[n].className =
(isNaN(numIn[n]))? 'isText':'isNumber';
}

}
</script>
</head>
<body>

<form name="formA" action="">
<div>
<input type="text" size="20" name="usernew">usernew</input><br>
<input type="text" size="20" name="QPSQTY">QPSQTY</input><br>
<input type="text" size="20" name="PTPS">PTPS</input><br>
<input type="text" size="20" name="PSSQTY">PSSQTY</input><br>
<input type="text" size="20" name="PSST">PSST</input><br>
<input type="text" size="20" name="ECQTY">ECQTY</input><br>
<input type="text" size="20" name="ECT">ECT</input><br>
<input type="text" size="20" name="EXQTY">EXQTY</input><br>
<input type="text" size="20" name="EXT">EXT</input><br>
<input type="text" size="20" name="INQTY">INQTY</input><br>
<input type="text" size="20" name="INTA">INTA</input><br>
<input type="text" size="20" name="SKQTY">SKQTY</input><br>
<input type="text" size="20" name="SKT">SKT</input><br>
<input type="text" size="20" name="CSQTY">CSQTY</input><br>
<input type="text" size="20" name="CST">CST</input><br>
<input type="text" size="20" name="total">total</input><br>
<input type="reset">
<input type="button" value="stuff"
onclick="SubmitSame(this.form);">
</div>
</form>
<span id="debugText"></span>
<br><br>

<input type="text" value="6" onblur="
document.getElementById('xx').innerHTML =
this.value + ' isNaN? : ' + isNaN(this.value);
">
<span id="xx"></span></body>
</html>

--
Fred

Jul 23 '05 #4
Rick wrote:
Wow that worked perfect.

What is the isNum for?
Nothing.

Thanks you very much!!!


You're welcome.

[...]
As a tip, here is a better way of doing what you are doing. It
does two things:

Puts your variables into objects, one for text one for numbers,
and uses the forms collection to avoid using getElementById.

You could include the DynWrite[1] function to provide
getElementById for those browsers that support document.all, but
I think the forms collection is simpler (assuming that you are
using a form...)

The function I've written just changes the style of a form
element depending on whether isNaN returns true or false, hardly
an exhaustive test of whether the input really is a number but
illustrative anyway.

I could have done the isNaN test when reading the values, but
that wouldn't show getting the values back from the object.

1. <URL:http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>Mod Style Play</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
..isText {font-weight: normal; color: blue;}
..isNumber {font-weight: bold; color: red;}
</style>
<script type="text/JavaScript">

function SubmitSame(theForm) {
// Just a guess, but are these the names
// of inputs in a form? If so, put them in an array

// all the text elements (just guessing)
var txtIn = {
'usernew':'','QPSQTY':'','PTPS':'','PSSQTY':'','PS ST':'',
'ECQTY':'','ECT':'','EXQTY':''
};
// all the number elements (just guessing)
var numIn = {
'EXT':'','INQTY':'','INTA':'','SKQTY':'','SKT':'',
'CSQTY':'','CST':'','total':''
};
var result, result1, result2, result3,
result4, result5, result6, result0, t, n;

// Now just loop through the elements of the objects and use
// the forms collection - no getElementById/all issues
for ( t in txtIn) {
txtIn[t] = theForm.elements[t].value;
}
for ( n in numIn) {
numIn[n] = theForm.elements[n].value;
}

// Test to see if isNaN & modify class accordingly
// Demonstrates looping through elements of an object
for (t in txtIn) {
theForm.elements[t].className =
(isNaN(txtIn[t]))? 'isText':'isNumber';
}
for (n in numIn) {
theForm.elements[n].className =
(isNaN(numIn[n]))? 'isText':'isNumber';
}

}
</script>
</head>
<body>

<form name="formA" action="">
<div>
<input type="text" size="20" name="usernew">usernew</input><br>
<input type="text" size="20" name="QPSQTY">QPSQTY</input><br>
<input type="text" size="20" name="PTPS">PTPS</input><br>
<input type="text" size="20" name="PSSQTY">PSSQTY</input><br>
<input type="text" size="20" name="PSST">PSST</input><br>
<input type="text" size="20" name="ECQTY">ECQTY</input><br>
<input type="text" size="20" name="ECT">ECT</input><br>
<input type="text" size="20" name="EXQTY">EXQTY</input><br>
<input type="text" size="20" name="EXT">EXT</input><br>
<input type="text" size="20" name="INQTY">INQTY</input><br>
<input type="text" size="20" name="INTA">INTA</input><br>
<input type="text" size="20" name="SKQTY">SKQTY</input><br>
<input type="text" size="20" name="SKT">SKT</input><br>
<input type="text" size="20" name="CSQTY">CSQTY</input><br>
<input type="text" size="20" name="CST">CST</input><br>
<input type="text" size="20" name="total">total</input><br>
<input type="reset">
<input type="button" value="stuff"
onclick="SubmitSame(this.form);">
</div>
</form>
<span id="debugText"></span>
<br><br>

<input type="text" value="6" onblur="
document.getElementById('xx').innerHTML =
this.value + ' isNaN? : ' + isNaN(this.value);
">
<span id="xx"></span></body>
</html>

--
Fred
Jul 23 '05 #5
*** Rick wrote/escribió (Mon, 21 Mar 2005 04:09:03 GMT):
I have been trying to get this code to work and the isNum seem to be giving
me a problem and I just cannot figure it out any help would me very much
appreciated!!


I can think of this:

function isNum(data){
return typeof(data)=='number';
}

document.writeln(isNum());
document.writeln(isNum(-2));
document.writeln(isNum(0));
document.writeln(isNum(33));
document.writeln(isNum(3.1416));
document.writeln(isNum('951'));
document.writeln(isNum('foo'));
document.writeln(isNum(document));
document.writeln(isNum(this));

Returns:

false
true
true
true
true
false
false
false
false
--
-- Álvaro G. Vicario - Burgos, Spain
-- Don't e-mail me your questions, post them to the group
--
Jul 23 '05 #6
JRS: In article <Vu****************@news.optus.net.au>, dated Mon, 21
Mar 2005 07:13:57, seen in news:comp.lang.javascript, Fred Oz
<Oz****@iinet.net.auau> posted :

You could include the DynWrite[1] function to provide
getElementById for those browsers that support document.all, ... 1. <URL:http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html>

There is a confusion somewhere.

DynWrite is in the FAQ proper, section 4.15 : it does not provide
getElementById, but it provides a means of doing one of the things that
is commonly done with getElementById.

There may be a different implementation of DynWrite in the Notes; but
any function of that name there should have the same parameters and
result.
I now think that it would be well to use inline code to provide
getElementById, and then to have a simple DynWrite using getElementById
(if wanted in more than one or two places; for clarity and compactness).

It's not generally sensible to use isNaN or its logical inverse to
validate numeric input, since in most cases one does not want to accept
all possible representations of all possible IEEE Doubles. Far better
to use RegExps : <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.

--
© 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 #7

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

Similar topics

8
by: Dirk Deimeke | last post by:
Hello, we have a database with one column CHAR(10), which contains numeric data (10 digits). (That was not my idea). Now, I have to find out all rows, which do not have numeric data in this...
4
by: FatboyCanteen | last post by:
If I have a textbox, Let use to input a text. I want to check the input text is integer type or no I use isnum() to validate it, but double type also pass the validation. I don't want to use Field...
4
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up ...
5
by: ulyses | last post by:
Hi i have got quite strange problem. I wrote programme which shows all runnign processes. This info is get from /proc dir. When a dir that is process dir is found stat file is read and pid, name...
5
by: achraf.b | last post by:
new javascript package to validate data # hasValidChars(string, characters, caseSensitive) # isIP(ip) # isAlpha(string) # isLetter(string) # isNotEmpty(string) #...
0
by: MohammadAlimoradi | last post by:
Hi to all friends. i convert this code from vb6 to vb.net and raise this error "'AddressOf' expression cannot be converted to 'Long' because 'Long' is not a delegate type." there is some code in...
61
by: warint | last post by:
My lecturer gave us an assignment. He has a very "mature" way of teaching in that he doesn't care whether people show up, whether they do the assignments, or whether they copy other people's work....
4
by: romcab | last post by:
Hi guys, Just want to ask your help about the error I encountered in Winsock connection. Here is the problem. When I added a button that has an event to connect to the server, I don't...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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.