as before the below code is in a while loop . it out puts values id=pro0 then next loop through i get id=pro1 and if i have another record i get id=pro3
print "<td><input style=\"text-align:center\" type=\"text\" name=\"productitemsupdate_$num\" value=\"$row[productitems]\" size=\"5\" id=\"pro$num\"></td>";
the above code works with
var pro = document.getElementById('pro0');
what im after is a loop in java script which will take the last $num from the php from and use that for the amount of times to loop the javascript function.
something like this i think
var i=0;
while (i<=$num) {
var pro[i] = document.getElementById('pro'[i]);
if (pro[i].value == "") {
inlineMsg('pro'[i],'This cannot Be blank'[i],10);
return false;
} else {
i++;
}
}
breaks when it is false when all fields are right it is true. if i get this working it will save me guessing how many variable to check.
i have tried this but i cant this working either
var i=0;
var pro[i] = document.getElementById('pro' + i);
for(var i = 0; i < <?php $num ?>; i++) {
if(pro[i].value == "")
alert("You entered: " + pro[i].value)
return false;
}
this works but only for the first line. if the 2nd line is emtpy and the first line is not it does not produce the alert
var i=0;
for(var i = 0; i < 3; i++) {
var pro = document.getElementById('pro' + i);
if(pro.value == "")
alert("You entered: " + pro[i].value)
return false;
}
i also changed the $num variable to a static number for my test record to see if it was my variable not being passed and it still did't work for the 2nd record any ideas
thanks
steve
working solution thanks for your help
var i=0;
var pro = [];
for(var i = 0; i < 2; i++) {
pro[i] = document.getElementById('pro' + i);
if(pro[i].value == ""){
alert("You entered: " + pro[i].value)
return false;}
}
return falseat the end of firstforloop run...ifblock.