Last active
January 2, 2017 04:52
-
-
Save bablukpik/c2edf36c1d37c49a44f598fc3fb160a8 to your computer and use it in GitHub Desktop.
These forms are for jquery and javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//01//serializeArray() // Here is not submit button hence all fields dada will not go to url | |
->The serializeArray() method creates an array of objects (name and value) by serializing form values. | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
$("button").click(function(){ | |
var x = $("form").serializeArray(); | |
$.each(x, function(i, field){ | |
$("#results").append(field.name + ":" + field.value + " "); | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form action="friendzict.com" method="get"> | |
First name: <input type="text" name="FirstName" value="Mickey"><br> | |
Last name: <input type="text" name="LastName" value="Mouse"><br> | |
</form> | |
<button>Serialize form values</button> | |
<div id="results"></div> | |
</body> | |
</html> | |
//OR | |
$( "form" ).submit(function( event ) { | |
console.log( $( this ).serializeArray() ); | |
event.preventDefault(); | |
}); | |
//02// Serialize and serializeArray is same | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
$("button").click(function(){ | |
$("div").text($("form").serialize()); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form action=""> | |
First name: <input type="text" name="FirstName" value="Mickey"><br> | |
Last name: <input type="text" name="LastName" value="Mouse"><br> | |
</form> | |
<button>Serialize form values</button> | |
<div></div> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment