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