Dynamic Assign Keypress event

W

winstontuck

Hi have an event called function allownumberonly(evt);

My html text input onkeypress calls this function.
onkeypress=allownumberonly(event)

I want to create a text input dynamically and set its onkeypress event
to the above function also passing the event.

Thanks
 
V

Vincent van Beveren

My html text input onkeypress calls this function.
onkeypress=allownumberonly(event)

I want to create a text input dynamically and set its onkeypress event
to the above function also passing the event.

Hi Winston,

inp = document.createElement('INPUT');
inp.setAttribute('type', 'text');
inp.setAttribute('name', 'input1');
inp.onkeypress = allownumberonly;

document.getElementById('myForm').appendChild(inp);

Vincent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,147
Latest member
CarenSchni
Top