Displaying new textbox on click button

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
asmitacp
Forum Newbie
Posts: 16
Joined: Wed Mar 26, 2008 7:36 am

Displaying new textbox on click button

Post 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 ?????????????
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Displaying new textbox on click button

Post by jayshields »

I'd advise using jQuery, look at this page in the API http://docs.jquery.com/Manipulation
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Displaying new textbox on click button

Post 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>
Post Reply