myTextField.id = 'myTextField'; myTextField.name = 'myTextField'; myTextField.style.width = '200px'; myTextField.onkeyup = 'example'; hey im creating form feilds with javascript for some reason i can change the onkeyup value does anyone know what i am doing wrong ??
sorry for double posting here is my code: var myTextField = document.createElement('input'); myTextField.type = 'text'; myTextField.id = 'myTextField'; myTextField.name = 'myTextField'; myTextField.style.width = '200px'; document.body.appendChild(myTextField); i just cnt figure out for the life of my how to add the event onkeyup via javascript rather than creating it in html manually >
you need to reference the function by its name if it is defined... (Not as a string though) so myTextField.onkeyup = 'example'; Code (javascript): should be (if you have a function named example) myTextField.onkeyup = example; Code (javascript): alternatively you can define on the fly a function for it like this myTextField.onkeyup = function(){ alert('keyup fired ;)'); // any code you like here... }; Code (javascript): take care