Hi I am trying to get my code to retrieve the key/ value pairs from a form on the page when a user clicks submit. I have been looking around and have tried a bunch of methods but keep getting errors such as :
Uncaught TypeError: Cannot use 'in' operator to search for '6' in success
My Code:
<form action="./blah" id="thisform">
<fieldset>
<legend>Place a Reservation</legend>
<label for="firstName">First name: </label>
<input id="firstName" type="text" placeholder="first name" autofocus="autofocus"
required="true" pattern="[a-z,A-Z]{8}"/><br/><br/>
<label for="lastName">Last name: </label>
<input id="lastName" type="text" placeholder="last name"
required="true" pattern="[a-z,A-Z]{1, 10}"/><br/><br/>
<label for="Phone">Phone number: </label>
<input id="Phone" type="phone-number" placeholder="(000)-000-0000" maxlength="10" minlength="10"
required="true" /><br/><br/>
<label for="Party">For how many people? </label>
<input id="Party" type="number" placeholder="#" min="1" max="12" value="1"
required="true"/><br/><br/>
<label for="date-of">Date of reservation </label>
<input id="date-of" type="date" placeholder="date of reservation" min="2016-01-01"
max="2016-12-30" value=""/><br/><br/>
<label for="Time-of">Time (24hr) </label>
<input id="Time-of" type="text" placeholder="00:00 " maxlength="20" /><br/><br/>
<input id="submit" type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</fieldset>
</form>
and then the script
<script>
/*<![CDATA[*/
$(document).ready(function() {
var submit = document.getElementById("submit")
submit.onclick = function(){
$.get("reserve.html", function(key, value){
$.each(value, function(key, value){
console.log(key, value);
});
});
};
});
/*]]>*/
</script>
I am quite lost and I know my code is off by a ways, any help is appreciated!
(also my first name input is not accepting what I enter and im not sure why)
Thanks!
It's a quit simple. Just use $('form').serialize()
like this:
$.get('reserve.html?'+$(form).serialize());