By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

How to get the name, class or id of a field in a form if serialize() in javascript?

Exequiel
100+
P: 287
Hello friends. . ! I want to know if how to get the name, class or id of a textfield in a form if we used the serialize() function in javascript. .
example:
we have this form
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="javascript:;" id="form">
  2. <input type="text" name="field_a" class="required" id="field_a"><br>
  3. <input type="text" name="field_b" class="required" id="field_b"><br>
  4. <input type="text" name="field_c" class="required" id="field_c"><br>
  5. <input type="submit" value="save" id="save">
  6. </form>
  7.  
and here is our javascript or jquery.
Expand|Select|Wrap|Line Numbers
  1. $('#save').click(function(event){
  2. var data = $("form#form").serialize();
  3.  
  4. //code to know the field's class, name or id,
  5. //alert(data.fieldname);
  6. });
  7.  
  8.  
How can I code to know the textfields class, name or id for a field and out put all the fields with a class="required"?
any suggestion are appreciated, thank you and advance. :)
May 29 '14 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
the answer is off the top of the jQuery documentation:
The .serialize() method creates a text string in standard URL-encoded notation.
May 30 '14 #2

Exequiel
100+
P: 287
I already solved this problem, , thanl you to your reply. :)
May 31 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.