1

code:

<input name="xy" size="2" type="text" />

this is meant to be a textbox, looks like and functions like one.

js:

  alert(document.getElementById("xy"));

and this returns null. If I try to get value of it or whatever, I simply get nothing.

Any reason ? (p.s: javascript works fine and its external)

1
  • There is no element with an id of "xy", so getElementById doesn't find one. Commented Jun 25, 2013 at 21:34

2 Answers 2

2

Just set an id :

<input id="xy" name="xy" size="2" type="text" />

getElementById take the id attribute, not the name.

Sign up to request clarification or add additional context in comments.

Comments

0

As our friend Ren said:

getElementById gets by the id, so you should set and id

But if you need to use the name atribute you could use: document.getElementsByName

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.