1

I need to loop through all textboxes on a page and gather their IDs so that I can have backward compatibility placeholder text in IE7.

Here is my code:

var boxes = document.getElementsByTagName('input');
for(i = 0; i < boxes.length; i++) {
placeHolder(boxes[i].id);
}

This works perfectly, but it also selects my submit button which I don't want.

The only thing my textboxes have in common is type="text". So is there anyway of getting just elements that are of the text type within Javascript?

1 Answer 1

5
var boxes = document.getElementsByTagName('input');
for(i = 0; i < boxes.length; i++) {
    if(boxes[i].type == "text") placeHolder(boxes[i].id);
}
Sign up to request clarification or add additional context in comments.

1 Comment

For the OP, given the above, consider storing a reference to the element so you don't have to use getElementById later.

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.