Hello friends.
I have a php form and using ajax/javascript function to do get request.
In form, there is a field name and checkbox, and In java script I have to get the fied name, check if the check box is clicked or not and add the paramater to url arguments, if checked.
echo "<tr><td>".$data[$j]['sname']."</td><td><input type=\"hidden\" name=\"field[$j]\" value=\"".$data[$j]['sname']."\"> <input type=\"checkbox\" id=\"val[$j]\"></input> </td>";
I dont know how many field will I have in my code, So i'm generating runtime name like field[0], field[1], and I'm expecting the same to read from java script like this.
var i=0;
var arg="update=1&";
while(document.getElementById(field[$i]) != NULL) {
var chk = document.getElementById(val[$i])
if( chk == 1)
arg+=arg+document.getElementById(field[$i])+"=1&";
i=i+1;
}
But things are not working as I would have wanted.
Javascript shows error that it can not read 'field'. I dont know why it goes to read 'field' and not 'field[0]',etc.
I may be doing something wrong in my PHP code or my java script.
Can anyone suggest what could be wrong?
Hemanshu