/    Sign up×
Community /Pin to ProfileBookmark

document.write and for loop issue

I wasnt sure what the subject should be. Here is my problem though:

<script language=”javascript”>
<!–
document.write(‘<form name=”form2″>’)
document.write(‘<table border=”1″ cellpadding=”5″ cellspacing=”0″ rules=”none”>’)

[COLOR=royalblue]//amount is a variable set somewhere else on the page[/COLOR]
for (i = 1; i<=amount; i++) {
document.write(‘<tr><td>Link ‘+i+'</td><td><input type=”text” name=”Link’+i+'”></td></tr>’)
}

document.write(‘</table>’)
document.write(‘</form>’)
[COLOR=royalblue]//can I do this? I am trying to create a script after the text boxes are generated, that will recognize “form2” and then create variables for each text box created with the for loop.

eventually I want the page to be able to reference each one of the text boxes so that I can use their value elsewhere on the page.
[/COLOR]
var script = ”
script += ‘<script language=”javascript”>’
script += ‘var link = document.form2.Link+i+.value’
script += ‘</script>’
document.write(script)
//–>
</script>

I appreciate any help
Thank You

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliMay 12.2004 — if you want to use "document.write" you will have to make sure that you know your logic.

document.write should be used (typically) before the page is loaded.Once the document is completely created and if you use document.write? it will over write the current document,hence resulting in not so desired results.
Copy linkTweet thisAlerts:
@ai3rulesauthorMay 12.2004 — I understand that, but in this case I am trying to create a basic generator for myself. That document.write section is in the <body> section and when it runs, it actually does add what I want to the page, not overwriting it.

I will attach the page so you could see what I am doing - I am new to this obviously and I realize I can still be completely wrong. Please let me know what you think. Thank you.

[upl-file uuid=5201f924-105e-4f92-bb55-641161320cf8 size=4kB]div links generator.txt[/upl-file]
×

Success!

Help @ai3rules 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,
)...