Friday 3 August 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...