473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need Help: Missing tags on dynamically added content

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.)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <div class="ctx02"><div class="lalign" id="control_box">
  5. </div></div>
  6. <br />
  7.  
  8. <script type="text/javascript">
  9. <!--
  10. var blocks_av = [];
  11.  
  12. function addEvent(target, etype){
  13.   var div = document.getElementById(target);
  14.   var num = (document.getElementById(target+'_track').value -1)+ 2;
  15.   var num_tracker = document.getElementById(target+'_track');
  16.   if(num > 99){num = 99;}
  17.   num_tracker.value = num;
  18.   var blockIDName = target+num+"block";
  19.   var newblock = document.createElement(etype);
  20.   newblock.setAttribute("id",blockIDName);
  21.   var str_numbered = blocks_av[target];
  22.   newblock.innerHTML = str_numbered.replace(/!@nu@!/, num);
  23.   div.appendChild(newblock);
  24.  
  25.   // Pops a new window with the dynamic HTML for debug (only IE)
  26.   var range = document.getElementById(target).innerHTML;
  27.   var frog = window.open("","wildebeast","scrollbars=1,resizable=1");
  28.   frog.document.open();
  29.   frog.document.write('<table>' + range + '</table>');
  30.   frog.document.close();
  31.  
  32. }
  33.  
  34. blocks_av['craft'] = '' + "\n" +
  35. '<td class="ctx07"><td>Craft <input type="text" name="craft!@nu@!-name" value="Enter Skill Name" class="i04">&nbsp;&nbsp;</td></td>' + "\n" +
  36. '<td class="ctx08"><input type="text" name="craft!@nu@!-ranks" value="" class="i05"></td><td class="ctx00"> + </td>' + "\n" +
  37. '<td class="ctx08"><input type="text" name="craft!@nu@!-miscmod" value="" class="i05">' + "\n" +
  38. '<input type="hidden" name="craft!@nu@!-abname" value="INT"></td>' + "\n" +
  39. '';
  40.  
  41. div = document.getElementById("control_box");
  42. div.innerHTML = '<span class="heading01">CONTROLS</span><br />' + "\n" +'<input type="hidden" value="1" id="craft_track" name="craft_track" />' + "\n" +
  43. '<a href="javascript:;" onclick="addEvent(\'craft\', \'tr\');">Add Another Skill: Craft</a><br />' + "\n\n" +
  44. '';
  45. //-->
  46. </script>
  47.  
  48. <table cellspacing="2">
  49.  
  50. <tbody>
  51.  
  52. <tr><td class="ctx07">Appraise&nbsp;&nbsp;
  53. <td class="ctx08"><input type="text" name="appraise-ranks" value="0" class="i05"></td><td class="ctx00"> + </td>
  54. <td class="ctx08"><input type="text" name="appraise-miscmod" value="0" class="i05">
  55. <input type="hidden" name="appraise-abname" value="INT"></td></tr>
  56.  
  57. </tbody>
  58.  
  59. <tbody id="craft">
  60. <tr><td class="ctx07">Craft <input type="text" name="craft0-name" value="Enter Skill Name" class="i04">&nbsp;&nbsp;</td>
  61. <td class="ctx08"><input type="text" name="craft0-ranks" value="0" class="i05"></td><td class="ctx00"> + </td>
  62. <td class="ctx08"><input type="text" name="craft0-miscmod" value="0" class="i05">
  63. <input type="hidden" name="craft0-abname" value="INT"></td></tr>
  64.  
  65.  
  66. </tbody>
  67.  
  68. </table>
  69.  
  70. </body>
  71. </html>
Sep 28 '06 #1
1 1722
acoder
16,027 Expert Mod 8TB
Instead of innerHTML, you may as well use DOM methods for creating and appending table cells. There seems to be incorrectly nested td elements within td elements.
May 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Robert Dell | last post by:
I have a problem comparing strings in an order form i'm writing. I want to give a running total at the bottom of the page and it appears to be working except it doesn't compare correctly (it...
2
by: andy | last post by:
I have user controls(.ascx) programmed to function as modules on the same page - default.aspx. As you would be well aware, default.aspx has the normal html stuff:- <%@ Page language="c#"...
4
by: Scott C. Reynolds | last post by:
Hi. I have created a templated control, and I want to know how i can set it up so that the projects consuming it will have all the same intellisense benefits of using any other server control. ...
3
by: Adrian Parker | last post by:
IE.. Tools -> Internet Options -> Settings Button -> Check for newer versions of stored pages = Never If a user changes thier settings to this, then pages are cached in IE. From what we've...
1
by: ankitvermamca | last post by:
I'm trying to dynamically add radio inputs to a form, but it's not working quite right. The code I have adds the radio buttons properly, but they are not selectable, and I can't seem to be able to...
23
by: Big Bill | last post by:
http://www.promcars.co.uk/pages/bonnie.php I don't believe they should be there, can I take them out without stopping the includes from functioning? I'm the (hapless) optimiser on this one... I...
0
by: Learner | last post by:
Hello, We use Master Pages in our website and need a page to be created dynamically. I am not sure where I am missing but I don't see any error and the controls on the page either! Here is my...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
4
by: bashetty | last post by:
Well its a strange problem i have, some of you might already faced it and have a solution. I have to maintain a set of unique "search key words" in meta tags for each content page in my site. With...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.