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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Exequiel
    Contributor
    • Jul 2012
    • 288

    #1

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

    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
    Code:
    <form method="post" action="javascript:;" id="form">
    <input type="text" name="field_a" class="required" id="field_a"><br>
    <input type="text" name="field_b" class="required" id="field_b"><br>
    <input type="text" name="field_c" class="required" id="field_c"><br>
    <input type="submit" value="save" id="save">
    </form>
    and here is our javascript or jquery.
    Code:
    $('#save').click(function(event){
    var data = $("form#form").serialize();
    
    //code to know the field's class, name or id,
    //alert(data.fieldname);
    });
    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. :)
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the answer is off the top of the jQuery documentation:
    The .serialize() method creates a text string in standard URL-encoded notation.

    Comment

    • Exequiel
      Contributor
      • Jul 2012
      • 288

      #3
      I already solved this problem, , thanl you to your reply. :)

      Comment

      Working...