Is there any such function to get all form tags?
by form tags I mean all <input>
, <select>
etc?
Thanks
Is there any such function to get all form tags?
by form tags I mean all <input>
, <select>
etc?
Thanks
var elements = getElementsByTagName("input")
.splice(getElementsByTagName("select"));
// splice to your hearts content
You could use jquery:
$(':input')
Otherwise, given the id of the form, all of its fields are given by
var formid = "foo";
var myform = document.getElementById( formid )
if (myform != null) {
// myform.elements is an array of the fields
}
And if you just wanted to find all the select elements in the page, use getElementsByTagName()
var all_selects = document.getElementsByTagName('select')
Using jQuery the following will make them pink:
$("input, select, textarea").css({background: "pink"});
A framework is overkill for this:
document.getElementsByTagName("input")
document.getElementsByTagName("select")
function getFormElements() {
var ary = [];
// use the full list of supported form elements below if this is not exhaustive
var elementNames = ['input','select','textarea','button'];
for (var i=0; i < elementNames.length; i++) {
ary.concat(document.getElementsByTagName(elementNames[i]));
}
return ary;
}