javascript - How to loop through all text box elements in a page source and find the names of all those text boxes? -
i writing program output number of gui elements in webpage if source page given input , should output names of text boxes.
the code wrote :
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>my app</title> <link rel="icon" type="image/x-icon" href="favicon.ico" /> </head> <body> <textarea id="textarea1"></textarea> <br /> <input id="submit1" type="submit" value="submit" /></div> <script> var $textarea = $('#textarea1'), $submit = $('#submit1'); $submit.click(function (e) { e.preventdefault(); sourcecode = $textarea.val(); var $searchobject = $('<div id="searching"></div>'); $searchobject.append($(sourcecode)); //search tags $(function () { var values = $('input[type=text]').map(function () { return this.name }).get() alert(values); }) alert("name of text field = " + $searchobject.find('[type=text]').attr('name')); alert("number of text boxes = " + $searchobject.find('[type=text]').length); alert("number of submit buttons = " + $searchobject.find('[type=submit]').length); alert("number of telephone entry fields = " + $searchobject.find('[type=tel]').length); alert("number of password boxes = " + $searchobject.find('[type=password]').length); alert("number of check boxes = " + $searchobject.find('[type=checkbox]').length); alert("number of radio buttons on page = " + $searchobject.find('[type=radio]').length); alert("number of drop down lists = " + $searchobject.find('select').length); alert("number of images on page = " + $searchobject.find('img').length); alert("number of hyperlinks on page = " + $searchobject.find('a[href]').length); alert("number of buttons = " + $searchobject.find('[type=button]').length); alert("number of date entry fields= " + $searchobject.find('[type=date]').length); }); </script> </body> </html>
i getting result 'domain' when run code:
$(function () { var values = $('input[type=text]').map(function () { return this.name }).get() alert(values); })
i giving source code of google signup page input. can me code loop through text boxes , list out names?
here simplest efficient:
document.addeventlistener('domcontentloaded',()=>{ var names = document.queryselectorall('input[type=text]').map((o)=>o.name); console.log(names); }); //prototype modifications nodelist.prototype.map = htmlcollection.prototype.map = array.prototype.map;
Comments
Post a Comment