OK, what is wrong with this?

Im sure its simple for you guys, but Im lost. thank you for showing me where I am going wrong.



Trying out new shit!



var nform = document.forms[0];
var str = nform.tb1.value; //shouldnt this assign the value of
//the text box to the variable?
// Im getting object undefined error

document.write(str.fontcolor=rgb(255,0,0))














Comments

  • : Im sure its simple for you guys, but Im lost. thank you for showing me where I am going wrong.
    :
    :
    :
    : Trying out new shit!
    :
    :
    :
    : var nform = document.forms[0];
    : var str = nform.tb1.value; //shouldnt this assign the value of
    : //the text box to the variable?
    : // Im getting object undefined error
    :
    : document.write(str.fontcolor=rgb(255,0,0))
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    Javascript is run as the browser reads it. Thus the assignment is run before the object tb1 is created, hence the unassigned. Solution: create a function in the header, and call that function in the onSubmit() event of the form.
  • : : Im sure its simple for you guys, but Im lost. thank you for showing me where I am going wrong.
    : :
    : :
    : :
    : : Trying out new shit!
    : :
    : :
    : :
    : : var nform = document.forms[0];
    : : var str = nform.tb1.value; //shouldnt this assign the value of
    : : //the text box to the variable?
    : : // Im getting object undefined error
    : :
    : : document.write(str.fontcolor=rgb(255,0,0))
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : Javascript is run as the browser reads it. Thus the assignment is run before the object tb1 is created, hence the unassigned. Solution: create a function in the header, and call that function in the onSubmit() event of the form.
    :
    Thank you, I tried putting it after the declaration of the tb1 and it still didnt work, so I didnt think that that was the problem. But when I did it your way with a function, it worked, thanks again. You'd have thought starting with c++ that I would have picked that up.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories