/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] assign id

Can someone help me with this script;

[code]
<script type=”text/javascript”>
<!–
var myArray = new Array();

myArray[0] = “Football”;
myArray[1] = “Baseball”;
myArray[2] = “Cricket”;

var bb = ‘<script type=”text/javascript”>function changeText2(){var userInput = document.getElementById(“userInput”).value;document.getElementById(“boldStuff2″).innerHTML = userInput;}</script><p>Welcome to the site <b id=”boldStuff2″>dude</b> </p> <input type=”text” id=”userInput” value=”Enter Text Here” /><input type=”button” onclick=”changeText2()” value=”Change Text”/>’
var linebreak = “<br />”;
document.write(“For loop code is beginning”);
document.write(linebreak);

for(i = 0; i < 3; i++){
document.write(myArray[i] + bb);
document.write(linebreak);
}
//–>
</script>
[/code]

the proroblem is: How can I assign different ID with a for loop cycle?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorJan 13.2010 — document.write() is not a dynamic method. What you want to do, after all?
Copy linkTweet thisAlerts:
@mgolemanovauthorJan 13.2010 — please execute the script and you will see the result

You will see a text and a little form that is used to change the text

i wann write mor than one of this txt/form/butt with a For loop

butt only the first is working(the text is changin)

theothers doesent work

can you help me

The main idea is:

In Array i have some names of a different products

i want to write this names and after every name should have a[form] and a [button]


exaple:

Football [form] [button]

Baseball [form] [button]

Cricket [form] [button]



if you write something in to the [form] and click the [button] the text bellow the button change with this one written in to the form.
Copy linkTweet thisAlerts:
@FangJan 13.2010 — An id and function must be unique to the document.
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;


&lt;style type="text/css"&gt;
* {margin:0;padding:0;}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;script type="text/javascript"&gt;
var myArray = new Array();

myArray[0] = "Football";
myArray[1] = "Baseball";
myArray[2] = "Cricket";

var linebreak = "&lt;br&gt;";
document.write("For loop code is beginning");
document.write(linebreak);

for(var i = 0; i &lt; 3; i++){
var bb = '&lt;p&gt;Welcome to the site &lt;strong id="boldStuff'+i+'"&gt;dude&lt;/strong&gt; &lt;/p&gt; &lt;input id="userInput'+i+'" value="Enter Text Here" type="text"&gt;&lt;input onclick="document.getElementById('boldStuff'+i+'').innerHTML=document.getElementById('userInput'+i+'').value;" value="Change Text" type="button"&gt;';
document.write(myArray[i] + bb);
document.write(linebreak);
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@mgolemanovauthorJan 13.2010 — 10x X 100
×

Success!

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