php how to get the type of form fields using jquery? -
i want name , value , type of fields in form. using following code helped me name , value type = "text" checkboxs , radio button too. want exact types of fields whether checkbox, radio or text. here code
<form action=""> <h1> try form</h1> first name: <input type="text" name="firstname" value="khan"><br> last name: <input type="text" name="lastname" value="wazir"><br> <input type="checkbox" name="vehicle" value="bike"> have bike<br> <input type="checkbox" name="vehicle" value="car" checked="checked"> have car<br> <input type="radio" name="gender" value="male" checked> male<br> <input type="radio" name="gender" value="female"> female<br> <input type="radio" name="gender" value="other"> other </form> <button>serialize form values</button> <div id="results"></div>
here script
<script> $(document).ready(function(){ $("button").click(function(){ var x = $("form").serializearray(); $.each(x, function(i, field){ $("#results").append(field.name + ":" + field.value + " :" + $( "input" ).attr( "type" ) + " "); }); }); }); </script>
change
$( "input" ).attr( "type" )
to
$( "input[name='" + field.name + "']" ).attr( "type" )
you must pick specify input type correct
Comments
Post a Comment