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 ?????????????
Displaying new textbox on click button
Moderator: General Moderators
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Displaying new textbox on click button
I'd advise using jQuery, look at this page in the API http://docs.jquery.com/Manipulation
Re: Displaying new textbox on click button
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>