Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find all form names on a page using jquery or javascript [closed]

How can I get all form names exists on a page using jquery??? can I use jquery input selector to find all forms on a page. for example I have a form on page like 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.

like image 232
Manish Jangir Avatar asked Mar 01 '12 09:03

Manish Jangir


People also ask

How can I get form data with javascript jquery?

The serializeArray() method creates an array of objects (name and value) by serializing form values. This method can be used to get the form data.

Can be used to find all form elements in an HTML document?

To get all <form> elements in the document, use the document. forms collection instead.


1 Answers

Read this: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery

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

To get all form names and store them in an array:

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

To select a form you already know the name of:

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

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

Or you can just select by id:

$('#searchForm')
like image 155
nnnnnn Avatar answered Oct 09 '22 07:10

nnnnnn