Page 1 of 1

add dynamic textbox

Posted: Wed Aug 17, 2011 12:50 am
by Sandip Ranipa
I am new to php and i want to know to how can i add new textbox to my web page when i press tab key from keyboard the new textbox should be created and this process should go on.

Re: add dynamic textbox

Posted: Wed Aug 17, 2011 11:27 am
by Jonah Bron
The easiest way to do that is to attach a keypress event. If it detects that a tab was clicked, it creates a clone of the textbox. This can be done pretty easily with Mootools. To listen for a tab, attach an event to it with addEvent.

Code: Select all

$('elementId').addEvent('keydown', function(event){
    if (event.key == 'tab' && !event.shift) {
        event.target.clone().inject(event.target, 'after');
        return false;
    }
});
Not sure if that actually works, haven't tested it. Replace 'elementId' with whatever the ID attribute of the first text box is set to. And put '[]' at the end of the name attribute.