/    Sign up×
Community /Pin to ProfileBookmark

how can i change a text box name with java script

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

[CODE]
function fgreet (){
var great = “great”;

document.form.T2.value=great;

}[/CODE]

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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FromU2MEDec 14.2005 — Try adding an id of the text fields ie. [B]id="T2"[/B] and so on. Then loop through the fields:

[CODE]<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>[/CODE]
×

Success!

Help @chrisG1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...