/    Sign up×
Community /Pin to ProfileBookmark

One line of code is killing me.

How can I add the value of str1 to “form” and “comment” in the javascript?

If [U][B]str1 = 1[/B][/U], I’d like to have: document.form[U][B]1[/B][/U].comment[U][B]1[/B][/U].value.replace(/n/g, “<br />”);
If [U][B]str1 = 2[/B][/U], I’d like to have: document.form[U][B]2[/B][/U].comment[U][B]2[/B][/U].value.replace(/n/g, “<br />”);
If [U][B]str1 = 5[/B][/U], I’d like to have: document.form[U][B]5[/B][/U].comment[U][B]5[/B][/U].value.replace(/n/g, “<br />”);

[code=html]
function addBlogcomments(str1,str2,str3)
{
var txt=document.form.comment.value.replace(/n/g, “<br />”);
}
[/code]

Thanks a lot ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@MalgrimJul 18.2009 — document.forms['form'+str1].elements['comment'+str1].value...
Copy linkTweet thisAlerts:
@MololoauthorJul 18.2009 — document.forms['form'+str1].elements['comment'+str1].value...[/QUOTE]

Thanks a lot Malgrim ! ?

Yes, I needed to because the user may call several ajax "comment forms" on my page.
×

Success!

Help @Mololo 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...