Hi,
I have 6 groups of inputs (each consisting of one textarea, one textbox and one dropdown). In the first group the elements have a name and id of TA1, TT1, TD1, the second TA2, TT2, TT3 all the way to TA6, TT6, TD6.
Within Groups 2-5 I also have a 'Move Down' image with an onclick event that triggers the function MoveDown(Grp) where Grp would be the Group number 2 to 5
my original code of...
...would work ok. For example, if I clicked on the 'Move Down' image in group 2 the code would move the contents of TA2, TB2 to TA3 and TB3, set the dropdown value of TD3 to that of TD2 and finally making TA2 and TB2 blank and set TD to the first value of the dropdown (which happens to be 'Please Select'). All fine so far...
But I have 6 groups and what if say groups 1-4 were populated and then I wanted to move groups 2, 3 and 4 down one so that I could put in new values in group 2
The code I have come up with is....
What I was hoping this would do is in the example I gave above... clicking on the Move Down image in group 2 should move the contents of each group down one starting with group 5 moving to 6 then 4 to 5, 3 to 4, 2 to 3 and then clear group 2.
I get no errors but IE hangs when the function starts. Have I created an endless loop? Where have I gone wrong.
Thanks
Mych
I have 6 groups of inputs (each consisting of one textarea, one textbox and one dropdown). In the first group the elements have a name and id of TA1, TT1, TD1, the second TA2, TT2, TT3 all the way to TA6, TT6, TD6.
Within Groups 2-5 I also have a 'Move Down' image with an onclick event that triggers the function MoveDown(Grp) where Grp would be the Group number 2 to 5
my original code of...
Code:
<script type="text/javascript">
function MoveDown(Grp)
{
NGrp = Grp+1
document.getElementById('TA'+NGrp ).value = document.getElementById('TA'+Grp).value
document.getElementById('TB'+NGrp ).value = document.getElementById('TB'+Grp).value
document.getElementById('TD'+NGrp ).selectedIndex = document.getElementById('TD'+Grp).selectedIndex
document.getElementById('TA'+Grp).value = ""
document.getElementById('TB'+Grp).value = ""
document.getElementById('TD'+Grp).selectedIndex = 0
}
</script>
...would work ok. For example, if I clicked on the 'Move Down' image in group 2 the code would move the contents of TA2, TB2 to TA3 and TB3, set the dropdown value of TD3 to that of TD2 and finally making TA2 and TB2 blank and set TD to the first value of the dropdown (which happens to be 'Please Select'). All fine so far...
But I have 6 groups and what if say groups 1-4 were populated and then I wanted to move groups 2, 3 and 4 down one so that I could put in new values in group 2
The code I have come up with is....
Code:
<script type="text/javascript">
function MoveDown(Grp)
{
for (i = 5; i = Grp; i--)
{
j= i+1
document.getElementById('TA'+j).value = document.getElementById('TA'+i).value
document.getElementById('TB'+j).value = document.getElementById('TB'+i).value
document.getElementById('TD'+j).selectedIndex = document.getElementById('TD'+i).selectedIndex
}
document.getElementById('TA'+Grp).value = ""
document.getElementById('TB'+Grp).value = ""
document.getElementById('TD'+Grp).selectedIndex = 0
}
</script>
What I was hoping this would do is in the example I gave above... clicking on the Move Down image in group 2 should move the contents of each group down one starting with group 5 moving to 6 then 4 to 5, 3 to 4, 2 to 3 and then clear group 2.
I get no errors but IE hangs when the function starts. Have I created an endless loop? Where have I gone wrong.
Thanks
Mych