form

Discussion in 'JavaScript' started by dean5000v, Feb 20, 2009.

  1. #1
    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 ??
     
    dean5000v, Feb 20, 2009 IP
  2. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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 >
     
    dean5000v, Feb 20, 2009 IP
  3. gnp

    gnp Peon

    Messages:
    137
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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
     
    gnp, Feb 20, 2009 IP