37 users online (2 members and 35 guests)  


  Results 1 to 2 of 2

Related

  1. generate tabs dynamically in java script    Forum: Javascript Forum
    Replies: 1
  2. Replies: 6
  3. Replies: 0
  4. Try Adsense to generate money    Forum: Internet Services
    Replies: 0
  5. Generate IP    Forum: General Discussion
    Replies: 3
  1. #1
    forjavascript's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2006
    Posts
    2

    dynamically generate a label using javascript

    how can i dynamically generate a label using javascript?

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: dynamically generate a label using javascript

    Hi there forjavascript,

    have a look at this example, it may suit your requirments...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    #inp0,#inp1,#inp2 {
       margin:5px 0;
     }
    </style>
    
    <script type="text/javascript">
    
    window.onload=function() {
      lab=new Array();
      words=new Array();
      labText=new Array();
      labText[0]=' : this is a label';
      labText[1]=' : this is another label';
      labText[2]=' : and this is a third label';
      inp=document.forms[0].getElementsByTagName('input');
    for(c=0;c<inp.length;c++){
      lab[c]=document.createElement('label');
      words[c]=document.createTextNode(labText[c])
      lab[c].appendChild(words[c]);
      document.getElementById('inp'+c).appendChild(lab[c]);
      }
     }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    
    <div id="inp0">
    <input type="text">
    </div>
    
    <div id="inp1">
    <input type="text">
    </div>
    
    <div id="inp2">
    <input type="text">
    </div>
    
    </form>
    
    </body>
    </html>