PDA

View Full Version : Writing to layers trouble???



bird_man11
Mar 21st, 2007, 01:26 AM
I have this code where i want to be able for the user to click a add button and it writes the text they inputed to a div layer in a table.

I've managed to get it working but when i add the <tr> and <td> tags it seems to not write them to the document

this is what i want written to the div layer

var text1 = "<tr><td><input type=hidden value=\"" + venue + " \" name=venues" + count + " \/><span class=formtext>" + venue + "<\/span><\/td><td><input type=button name=del[] value=Del onclick=delit(";

var text2 = ",\'" + id + "\') \/><\/td><\/tr>";

when i alert(text1 + text2) it outputs the way i want but when written to the layer it shows up like this

<input type=hidden value="Blah" name=venues3 /><span class=formtext>Blah</span></td><td><input type=button name="del[] value=Del onclick=delit(177,177,'venuediv') /></td></tr>

although when i add a second venue it writes the tags for the second entry onwards, so its only the first entry that has the problem.

<input type=hidden value="Blah" name=venues3 /><span class=formtext>Blah/span></td><td><input type=button name="del[] value=Del onclick=delit(177,177,'venuediv') /></td></tr><tr><td><input type=hidden value="Blah" name=venues3 /><span class=formtext>Blah/span></td><td><input type=button name="del[] value=Del onclick=delit(177,177,'venuediv') /></td></tr>


Hope someone can be of some help, it would be much appreciated.

Cheers in advance

rwedge
Mar 21st, 2007, 05:58 AM
The table row tags should show if they are part of the text1 string. Could be something else in your code causing a problem.
In your posted code there are some errors in the quotes. If you use single quotes to delimit your strings it may help save some keystrokes and be easier to read, plus you are escaping when you do not need too.

Here's an example.
<form name="f" id="f">
<textarea name="a" id="area" cols="70" rows="10"> </textarea>
</form>

<script type="text/javascript">
var id = 'IdHere';
var venue = 'VenueHere';
var count = 3;
var text1 = '';
for (var i=0;i<count;i++) {
text1 += '<tr><td><input type="hidden" value="'+ venue +'" name="venues'+ i +'" id="venues'+ i +'" /><span class="formtext">'+ venue +'</span></td><td><input type="button" name="del[]" id="del[]" value="Del" onclick="delit(';
text1 += '\''+ id +'\')" /></td></tr>\n';
}
document.f.area.value=text1;
</script>