From: Rick on
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 ; }
}



From: Fred Oz on
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
From: Rick on
Wow that worked perfect.

What is the isNum for?

Thanks you very much!!!


"Fred Oz" <OzFred(a)iinet.net.auau> wrote in message
news:KDs%d.440$Zn.26430(a)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


From: Fred Oz on
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':'','PSST':'',
'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
From: Alvaro G Vicario on
*** 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
--