Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Ballymena, N.Ireland
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Looping difficulties

    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++)
    str+=(/tick\.gif/i.test(imgs[j].src)?'True':'False')+(j<imgs.length-1?',':'');
    str+=i<rows.length-1?';':'';
    }
    frm.elements['imagestates'].value = str;

    document.all.form1.submit();

    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.
    Eg.
    <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
    se,4,'help';

    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
    Last edited by karolmcauley; 07-13-2004 at 12:20 PM. Reason: Resolved***********

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    Ballymena, N.Ireland
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Resolved

    Panic over!!

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

    Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •