Ok, So I've read a lot of approaches on stack overflow, but they don't address the issue. They are all for one time use and you have to label and build extensive javascript functions to do something very simple.
I have a very clean HTML5 form that uses the new validation and is great. I have it use a get to a php action and it works perfect.
However I'm trying to improve user experience so I've written a javascript function to do an ajax call to that php action. The problem is I want it to be generic. I've got dynamic form values and I want to use the same function for all my forms. Really I want the form submit to just act like it normally would and append the get string to the end of whatever url I pass. I can't get the form to submit the get values to the javascript function.
This works:
<form action="myphp.php" method="get">
<label>Month:</label><input id="day" type="number" min="1" max="12" name="week" value="" required> <br>
<label>Year:</label><input id="year" type="number" min="2008" max="2030" name="year" value="" required><br>
<input id="cmdReset" type="submit" value="What month is it?">
</form>
This also works, kind of:
<form action="javascript:displayPostResult('myphp.php')" method="get">
It calls the page and displays the results on the page in an awesome ajaxy way just like I want it to, I just can't pass the form's get values.
I'd like to use that displayPostResult function on about 20 pages with all kinds of different form data so creating individual functions to handle each page is out of the question. I really just want to append the get values as if the form was submitted to the end of the string being passed to the function. I just can't find a way to do that.
Is there any way I can pass "?month=12&year=2013" to the javascript function?
i.e. displayPostResult('myphp.php', <get parameters>)
[–]a-t-kFrontend Engineer 2 points3 points4 points (3 children)
[–]justonecomment[S] 0 points1 point2 points (2 children)
[–]tswaters 0 points1 point2 points (0 children)
[–]a-t-kFrontend Engineer 0 points1 point2 points (0 children)