...

View Full Version : Document Object Model?



Dawnyy
07-07-2006, 12:10 PM
I have an internet form with many input boxes and I need to check most of them to see if they're numeric.

I have written an isnumeric function and I realise I could type a line such as

If (IsNumeric(document.getElementById( TagName ).value)) {
return true
else
return false
}



for each one individually to test, but since there are hundreds of fields, I was wondering if there was an easier way of doing this

Is there any way of looping through the elements (each input box) on my form?

Any example code would be a great help.

Many Thanks
Dawn

rlemon
07-07-2006, 02:52 PM
var inputs = document.forms[0].getElementsByTagName("input");
for (i = 0; i < inputs.length; i++) {
if(inputs[i].type == "text") if(IsNumeric(inputs[i].value))
alert("input #" + i + " is numeric");
// false statement below
}

Kor
07-14-2006, 10:36 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/JavaScript">
function valid(f) {
if (!/^\d*$/.test(f.value)) {
alert("Only integer numbers allowed!");
f.value = f.value.replace(/[^\d]/g,"");
}
}
</script>
</head>
<body>
<input type="text" onkeyup="valid(this)">
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum