user3420034
user3420034

Reputation:

Loop through visible input elements in a form in Javascript?

I'm trying to loop through all visible inputs within a form and set their value to be empty. What I have doesn't seem to work for text inputs, it returns undefined. Any ideas how to do this?

Upvotes: 0

Views: 1732

Answers (2)

Joseph
Joseph

Reputation: 119877

jQuery has a :visible selector as well as an :input selector. In addition, most jQuery methods operate on the entire set. val() can be used directly rather than looping through the set.

currentForm.find(':input:visible').val('');

Upvotes: 2

Greg Valcourt
Greg Valcourt

Reputation: 731

Textbox inputs would have a tagName of "textarea". Not sure why the other text types aren't working. Have you tried:

childs[i].values = '';

?

Upvotes: 0

Related Questions