Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help: Missing tags on dynamically added content

Status
Not open for further replies.

darwin2kx

Technical User
Sep 28, 2006
3
CA
I have a problem that I've been tracking down for a while now. I'm working on a script that dynamically adds blocks for data entry to a page. This script works on one page but not another. For some unknown reason, it seems to be stripping out tags. (And yes, I know the code looks a little messy. It's dynamically created by PHP, and I have to tidy it up a bit still.)

What seems to happen is when a link is clicked to add an input, it appears to strip off the <td> tag.

Any help is appreciated.

(Warning for IE users: The following code may not work proper for you. For some reason when I put it all together for this post, something went wonky. Works fine in Firefox though.)

Code:
<html>
<body>

<div class="ctx02"><div class="lalign" id="control_box">
</div></div>
<br />

<script type="text/javascript">
<!--
var blocks_av = [];

function addEvent(target, etype){
  var div = document.getElementById(target);
  var num = (document.getElementById(target+'_track').value -1)+ 2;
  var num_tracker = document.getElementById(target+'_track');
  if(num > 99){num = 99;}
  num_tracker.value = num;
  var blockIDName = target+num+"block";
  var newblock = document.createElement(etype);
  newblock.setAttribute("id",blockIDName);
  var str_numbered = blocks_av[target];
  newblock.innerHTML = str_numbered.replace(/!@nu@!/, num);
  div.appendChild(newblock);

  // Pops a new window with the dynamic HTML for debug
  var range = document.getElementById(target).innerHTML;
  var frog = window.open("","wildebeast","scrollbars=1,resizable=1");
  frog.document.open();
  frog.document.write('<table>' + range + '</table>');
  frog.document.close();

}

blocks_av['craft'] = '' + "\n" + 
'<td class="ctx07">Craft <input type="text" name="craft!@nu@!-name" value="Enter Skill Name" class="i04">&nbsp;&nbsp;</td>' + "\n" + 
'<td class="ctx08"><input type="text" name="craft!@nu@!-ranks" value="" class="i05"></td><td class="ctx00"> + </td>' + "\n" + 
'<td class="ctx08"><input type="text" name="craft!@nu@!-miscmod" value="" class="i05">' + "\n" + 
'<input type="hidden" name="craft!@nu@!-abname" value="INT"></td>' + "\n" + 
'';

div = document.getElementById("control_box");
div.innerHTML = '<span class="heading01">CONTROLS</span><br />' + "\n" +'<input type="hidden" value="1" id="craft_track" name="craft_track" />' + "\n" +
'<a href="javascript:;" onclick="addEvent(\'craft\', \'tr\');">Add Another Skill: Craft</a><br />' + "\n\n" +
'';
//-->
</script>

<table cellspacing="2">

<tbody>

<tr><td class="ctx07">Appraise&nbsp;&nbsp;
<td class="ctx08"><input type="text" name="appraise-ranks" value="0" class="i05"></td><td class="ctx00"> + </td>
<td class="ctx08"><input type="text" name="appraise-miscmod" value="0" class="i05">
<input type="hidden" name="appraise-abname" value="INT"></td></tr>

</tbody>

<tbody id="craft">
<tr><td class="ctx07">Craft <input type="text" name="craft0-name" value="Enter Skill Name" class="i04">&nbsp;&nbsp;</td>
<td class="ctx08"><input type="text" name="craft0-ranks" value="0" class="i05"></td><td class="ctx00"> + </td>
<td class="ctx08"><input type="text" name="craft0-miscmod" value="0" class="i05">
<input type="hidden" name="craft0-abname" value="INT"></td></tr>

</tbody>

</table>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top