I have a table with 15 rows containing a number of textboxes. If I change a numerical value in the last box in a row then, from the next row down to the end, the values must start from one more than that value, and increment in each row. Thus, eg, I want this change to occur when I alter the 2 to 5 in the second row:
1 1
2 5
3 6
4 7
etc
The cell code (generated with php) is:
for ($i=0;$i<15;$i++){
........
echo "<input name='$name1' id='$name1' value='$i'
onchange='AdjustTracks($i);alert(\"here\");'>";
........
}
The javascript is:
<head>
<script type="text/javascript">
function AdjustTracks(i){
var box=document.getElementById("workData"+i+"_5");
var endTr=parseInt(box.value);
for (j=i+1;j<15;j++){
endTr=endTr+1;
box=document.getElementById("workData"+j+"_5");
box.value=endTr;
}
return;
}
</script>
</head>
When I change one of the values, the javascript function is called and the other values change correctly. As soon as I release the alert, however, all the boxes return to their original values. What is happening?
Thanks
I suspect that your action in dismissing the alert() is causing the <form> to be "submitted" with no 'action' attribute set, so the page is reloading, which restores all of the default values. It's hard to say with just the code you posted. Try adding "return false;" after the alert() call in your 'onchange' setting.
Rick
Thanks. Your comment about the form submitting solved it. I realised I was clicking Enter to move off the changed field which resubmitted it. Thanks for the Christmas present.
Tony
Bookmarks