Friday, August 3, 2018

javascript - Regexp to pull input tags out of form

Why can't you just use the DOM?


var inputFields = document.getElementById('form_id').getElementsByTagName('input');
for (var i = 0, l = inputFields.length; i < l; i++) {
// Do something with inputFields[i] ...
}

If you must use regex:


var formHTML = document.getElementById('form_id').innerHTML;
var inputs = formHTML.match(//g);

Note, the above regular expression is not reliable and will not work in ALL situations, hence why you should use the DOM! :)

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...