"POLILOP" <fmatosic@@inet.hr> wrote in message
news:dj**********@ss405.t-com.hr...
Is there a way to get only the txt fields in my form and check if they are
empty without having to
pass there names or there id's to the function. Something like to pass the
form name and then
get all the text fields from the form and check if they are empty?
Will this help? Watch for word-wrap.
<html>
<head>
<title>formelem.htm</title>
<script type="text/javascript">
function test(form) {
for (var i=0; i<form.elements.length; i++) {
if (form.elements[i].type == "text") {
if (form.elements[i].value == "") {
alert(form.elements[i].name + " is empty!");
return false;
}
}
}
return true;
}
</script>
</head>
<body>
<form action="" method="get" name="form1" onsubmit="return test(this)">
<b>Part Number : </b>
<select name="Part_Number">
<option value="">
<option value="Product 1">123
<option value="Product 2">456
<option value="Product 3">789
</select>
<br><b>Product Description : </b>
<input type="text" name="Product_Description" value="">
<br>
<input type="submit" value="Submit">
<input type="reset">
</body>
</html>