The following method is called from two different buttons’s onclick event:
this.changeSearch = function(obj, $tag) {
var url = jQuery('#admin_url').val() + '/tools.php?page=cemeteriat&cempage=' + $tag;
window.location=url;
return;
};
In one instance, whether the form is populated or not, the button press results in the expected GET call. In the other, if the form is populated, instead of the GET to the expected URL, a POST is executed to the url assigned in the action attribute of the form. what the…
I’ve traced the code, and both times the URL above is assigned the same value! I have tried using document.location, window.location, and window,location.href with no change in behavior. does not seem t be browser specific.
What could cause the assigned of the windows.location to result in a POST of the form instead of the expected GET?
It’s because one of your buttons is the submit button for the form, so it’s getting submitted and it’s never really getting to the code you’re showing.
You should hook to the form’s submit event and call
event.preventDefault();You cannot prevent form submission from the click handler for the submit button.Alternatively, you can make the button not be of type submit.
Another option is to handle the submit event and to change the form from the submit handler to point to the correct URL and method of submission