I have a PHP script that prints out a <div> with form elements containing data for each entry. Very simplified, this is what it's like:
...etc, etc.
I'd like to use Javascript to access the values from some of these form elements. So I tried using document.getElementById("box_1").getElementsByName("title").value, but that doesn't work.
How can I do this? I don't really want to give every <input> an id like "title_4" and "article_4" and use getElementById(), because that seems less structured, you know?
Code:
<div id="box_1">
<input name="title" type="text" value="Some title from the db"/>
<textarea name="article">Article text here</textarea>
</div>
<div id="box_2">
<input name="title" type="text" value="Some other title from the db"/>
<textarea name="article">Article number 2 here</textarea>
</div>
...etc, etc.
I'd like to use Javascript to access the values from some of these form elements. So I tried using document.getElementById("box_1").getElementsByName("title").value, but that doesn't work.
How can I do this? I don't really want to give every <input> an id like "title_4" and "article_4" and use getElementById(), because that seems less structured, you know?