Solved

Write input field using InnerHTML

Posted on 2008-10-16
2
448 Views
Last Modified: 2012-05-05
Hi Experts,

I'm having problems with the script below, i am trying to write the contents of the loop to the <td id="909"> tag. But nothing happens and the script is behaving very strangely. Just needed some advice on how to approach this.
<html>

 

<script>

 

function listing() {

   var user_id = "1##2##3##4##5##6##7##8##9##10";

   var a = user_id.match(/[^#]+/g);

   document.open();

   for (var index = 0; index < a.length; index++)

   {

      document.getElementByid('909').innerHTML = ("<input name='" + a[index] + "' value='" + a[index] + "'>");

   }

   document.close();

 

   }

</script>

 

 

 

<body>

<a href="#" onclick="listing();return false;">test</a>

<table><tr><td id="909"></td></tr></table>

</body>

</html>

Open in new window

0
Comment
Question by:agulaid
2 Comments
 
LVL 4

Accepted Solution

by:
sijishJohn earned 500 total points
ID: 22729316
change your script like this...
function listing() {

   var user_id = "1##2##3##4##5##6##7##8##9##10";

   var a = user_id.match(/[^#]+/g);  

       for (var index = 0; index < a.length; index++)

       {

          document.getElementById('909').innerHTML += "<input name='" + a[index] + "' value='" + a[index] + "'>";

       } 

   }

Open in new window

0
 

Author Closing Comment

by:agulaid
ID: 31506654
Perfect
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now