Page 1 of 1

Displaying new textbox on click button

Posted: Fri Feb 27, 2009 5:11 am
by asmitacp
I am devloping a PHP module where I want multiple textboxes on click button.
i.e.
user can add texbox onclick of button each time.
Can anybody help ?????????????

Re: Displaying new textbox on click button

Posted: Fri Feb 27, 2009 5:48 am
by jayshields
I'd advise using jQuery, look at this page in the API http://docs.jquery.com/Manipulation

Re: Displaying new textbox on click button

Posted: Fri Feb 27, 2009 2:59 pm
by kaszu
To solve this problem we don't need several kb framework. For beginners it would be easier/faster/etc., but not as useful as learning how to do it without framework.

Code: Select all

<div id="container"></div>
<button id="myButton" onclick="addTextArea();">Add one more</button>  <!-- here SHOULDN'T be used onclick, but instead in JS should be used addListener. This was just shorter -->
<script type="text/javascript">
var inp_index = 1;
function addTextArea () {
    var inp = document.createElement('TEXTAREA');
    inp.name = 'my_textarea_' + inp_index;
    //+other attributes
   
    document.getElementById('container').appendChild(inp);
 
    inp_index++;
}
</script>