View Full Version : Looping difficulties

07-13-2004, 11:54 AM
Scenario is:

I have the function below which loops round table body images (tick.gif or cross.gif) and if the table cell contains a tick set a value to true else set it to false. Then equate all the images to a string variable and pass it to a hidden input for submit with the form.

function getImageStates(frm)
var str='';
var tb = (document.getElementById('Security')).getElementsByTagName('tbody')[0];
var rows = tb.getElementsByTagName('tr');
for(var i=0; i<rows.length; i++)
{ var imgs = rows[i].getElementsByTagName('img');
for(var j=0; j<imgs.length; j++)
frm.elements['imagestates'].value = str;


return true;

This works fine and submits the form so that i can split the true false array down so as to use this to save to my db. However, as previously mentioned i also need to pass certain values (seclevelRef and secOptionRef) so that per true/false value i know what to update the database with. These variables are loaded from a db proc and populate hidden input fields attached to the tick/cross image.
<td align="center"><input type="hidden" name="initialtick" value="<%=SecLevelRef%>,'<%=SecOptRef%>'"><img src="images/Tick.gif" onclick="flip(this)"></td>

Now in order to get their values and concatenate them with the true/ false what do i do????? How do i ammend makedata(frm) function above so that if SeclevelRef = 1 and SecOptionRef ='hello' my imagestates str will look like: (first tr of table)- True,1,'hello',false,2,'there',True,3,'vladdy',fal

var inputs = rows[i].getElementsByTagName('input');

This may get all the input fields into a variable but how to i loop round them getting their values and concatenate them with the true or false part of makedata(frm) function??? Is it possible? Do you know? Is there an alternative?

Many thanks in advance

07-13-2004, 12:21 PM
Panic over!!

I have managed to resolve the issue above and solve my problem.