DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Generating Fields On the Fly (http://www.daniweb.com/forums/thread149948.html)

yasmena Oct 8th, 2008 9:40 am
Generating Fields On the Fly
 
im asking the user to enter the number of fields he want to generate and i need to take this number and generate him the fields when he click Submit

can anyone Help Me

Shanti Chepuru Oct 8th, 2008 10:00 am
Re: Generating Fields On the Fly
 
you mean dynamic text box generation...
or
what do you mean by fields here?

yasmena Oct 8th, 2008 10:08 am
Re: Generating Fields On the Fly
 
yeah thats what i mean dynamic text box generation

Shanti Chepuru Oct 8th, 2008 10:19 am
Re: Generating Fields On the Fly
 
hello..
try this code:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Third Santor</title>
<script>
  function generate(){
    var myDiv = document.getElementById('someid');
      var objTextArea = document.getElementById('mem1');

    var list = objTextArea.value.split('\n');

     
      var tbody = document.createElement('tbody');

      for(var i=0; i<list.length; i++){     

        var cell1 = document.createElement('td');
        var label = document.createTextNode(list[i]);
        cell1.appendChild(label);

        var cell2 = document.createElement('td');
        var textbox = document.createElement('input');
        textbox.type = 'text';
        textbox.id = list[i];
        cell1.appendChild(textbox);

        var row = document.createElement('tr');
        row.appendChild(cell1);
        row.appendChild(cell2);
       
        tbody.appendChild(row);
      }

    var table = document.createElement('table');
      table.border = 1;
      table.appendChild(tbody);

    /*  var submit = document.createElement('input');
    submit.type = 'submit';
      submit.value = 'Submit';
*/
      myDiv.appendChild(table);
      myDiv.appendChild(submit);     
  }
</script>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<form name="frm1" method="post" action="" onsubmit="return ">
<textarea name="mem1" id="mem1" rows="10" cols="30"></textarea>
<input type="button" value="Generate" onclick="generate();">
</form>
<DIV id="someid"></DIV>
</body>
</html>
and also check:
http://www.daniweb.com/forums/thread135356.html


All times are GMT -4. The time now is 3:42 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC