Reputation: 1622
This is my form
<form id=edit method=post accept-charset=UTF-8 action=>
<input type=hidden name=video_id[0] value=K94KNsN43BU><p>Title<br>
<textarea rows=1 cols=40 id=title_0 name=title[0]>drugi</textarea>
<input type=button value=Copy onclick=copyTitle()><p>Description<br>
<textarea rows=4 cols=40 id=desc_0 name=description[0]>drugi uiuhuih</textarea>
<p>Tags (separated by coma)<br>
<textarea rows=2 cols=40 id=tags_0 name=tags[0]>iko koko mooko</textarea><hr>
<input type=hidden name=video_id[1] value=oYNIKpdTT9w><p>Title<br>
<textarea rows=1 cols=40 id=title_1 name=title[1]>prvi oijoi</textarea>
<p>Description<br>textarea rows=4 cols=40 id=desc_1 name=description[1]>prvi</textarea>
<p>Tags (separated by coma)<br><textarea rows=2 cols=40 id=tags_1 name=tags[1]>prvi, koko, youtube, impotr</textarea><hr>
<input type=submit name=submit2 value=Submit></form>
what I'm trying to do is to make button that copies text from first textarea wich can be for example Title to all other Title textareas that appears on the page and their number depends on the choice of user.
This is the javascript
function copyTitle() {
var title = document.getElementById("title_0").value;
var count = document.getElementById("edit").lenght/3;
var i=0;
for (i=0;i<count;i++) {
var text = document.getElementById("title_"+i);
text.value = title;
}
}
I'm dividing form lenght by 3 because there are Title, Description and Tags textareas. What I'm doing wrong?
Upvotes: 0
Views: 299
Reputation: 11908
A whole lot. Let's start by putting quotes around property values (like this: id="title_0"
).
Then for why your script is failing:
It's length
not lenght
You are forgetting the hidden input, the copy button and the submit button, which means you have to subtract 3 from the length before dividing it by 3 (or subtract 1 afterwards, obv.). That is, if you want to solve this problem in such an ugly manner (which, for example can't handle an extra hidden input field in the form)
Upvotes: 1