Click to See Complete Forum and Search --> : how can i change a text box name with java script


chrisG1
12-14-2005, 11:39 AM
Hi,

My script is populating a few text boxes with the same data. At the moment i can only get it to do the first text box without writing the same code again and again.

see cod below


function fgreet (){
var great = "great";

document.form.T2.value=great;

}

What i would like to do is something which would increase number after the T by 1 each time its loop through. Don't know where to start though!

Please help

FromU2ME
12-14-2005, 12:00 PM
Try adding an id of the text fields ie. id="T2" and so on. Then loop through the fields:

<script language="JavaScript">

function fgreet (){
var great = "great";

for (i=0; i<totalFields; i++) { // Change 'totalFields' to the # of text fields

var Ti = eval("T" + i);
document.getElementById(Ti).value = great;

}

}
</script>