PDA

View Full Version : help with getElementByTagName



homerUK
Oct 12th, 2004, 02:49 PM
hey guys, I have the following code:



var the_inputs = document.getElementsByTagName("input");
for (var n=0; n<the_inputs.length; n++)
{
if (the_inputs[n].type == "text") {

if (substr(the_inputs[n].name,0,4) == "prod_")
{
if (the_inputs[n].value == "")
{
alert("Bit missing");
}
}
}
}

it basically is meant to go through each element on the page which starts with "prod_", eg:

<input type="text" name="prod_item_one">
<input type="text" name="prod_this_another_item_q21">

it is meant to look at all the text inputs, which have "prod_" as the first 5 characters and check if they have a value in them...

where am I going wrong?! cheers for any help :)

liorean
Oct 12th, 2004, 02:54 PM
if (substr(the_inputs[n].name,0,4) == "prod_")
-->
if (the_inputs[n].name.substr(0,4) == "prod_")