|
-
February 5th, 2010, 03:22 AM
#1
HTML tags break javascript
Hello,
I have a quick question that I cannot for the life of me figure out.
The following is my java code to extend a form:
Code:
<script type="text/javascript">
var counter = 0;
function add_event() {
counter++;
var newFields = document.getElementById('add_event').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
if (theName)
newField[i].name = theName + counter;
}
var insertHere = document.getElementById('add_event');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
</script>
The script essentially acts on this sample of html:
Code:
<li>
<label for="title">Title: </label><input type="text" name="title" value="" />
</li>
<li>
<label for="time">Time: </label><input type="text" name="time" value="" />
</li>
Everything works fine except for the counter/adding on to theName ( newField[i].name = theName + counter).
I know exactly what the problem is... I just don't know how to fix it. If I remove the li tags, the counter will work fine and increment each "name". As soon as I put the li (see code above) tags back (or any html tag - I have tested others as well) - it breaks again and won't increment the name - it just submits the names without numbers and alas I have no usable post data.
Does anyone have any clue how to keep the html formatting there and still get the counter to increment the name?
-
February 5th, 2010, 05:28 AM
#2
Re: HTML tags break javascript
JFYI - Javascript is not Java.
It is better to have an approximate answer to the right question than an exact answer to the wrong one...
J. Tukey
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
February 5th, 2010, 05:30 AM
#3
Re: HTML tags break javascript
Even more proof that I don't know much about java
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|