Find all form names on a page using jquery or javascript

How can I get all the form names on a page using jquery ??? can i use jquery input selector to search for all forms on the page. for example, I have a form on the page as shown below

<form name="searchForm" id="searchForm" action=""> <input type="text" name="inputname" /> </form> 

now i want to find the form name "searchForm" using jquery. so how can i do this ??

Please help me. thanks.

+6
source share
5 answers

Read the following: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery

Your question is not clear: the first sentence sounds like you want to use jQuery to get a list of all the form names on the page, but then you say you want to find "searchForm", meaning that you want to select a form that you already know the name.

To get all the form names and save them in an array:

 var names = []; $("form").each(function() { names.push(this.name); }); 

To select a form that you already know, name:

 $('form[name="searchForm"]') // or if the name is in a variable: var name = "searchForm"; $('form[name="' + name + '"]') 

Or you can simply select by id:

 $('#searchForm') 
+11
source
 $("form").map(function(idx, form){ return form.name; }); 
+2
source

Using jquery:

 $('form[name="searchForm"]') 

Using vanilla javascript:

 document.getElementsByName('searchForm') 
+1
source

To get all forms named searchForm, your selector will be:

 $('form[name="searchForm"]'); 

Hope this helps you!

0
source

try:

 $('form[name="searchForm"]') 

Uses equals selector attribute

0
source

Source: https://habr.com/ru/post/909723/


All Articles