1

-- This is not a duplicate question. Please read the question thoroughly --

I am trying to post a form dynamically (dynamic form action) using jQuery which works well in almost all browsers, but doesn't work in Microsoft Internet Explorer and Edge.

  • It just refreshes the page rather than posting when using the above browsers.
  • Don't see any JavaScript errors in browser console.

Here is a code:

<form id="booking" name="booking" method="post">
<!-- form data goes here -->
</form>

<script>
var $j = jQuery.noConflict();
$j(document).ready(function() {
    $j('#booking').submit(function() {

        var theForm = document.getElementById("booking");
        var x = document.forms["booking"]["chargetotal"].value;
        var payment_method = document.forms["booking"]["payment"].value;

        if (payment_method == "Card") {
            $j(this).attr("action", "<?php bloginfo('url'); ?>/confirmation");
        }
        if (payment_method == "Transfer") {
            $j(this).attr("action", "<?php bloginfo('url'); ?>/confirmation-bacs");
        }
        if (x == '0.00' || x == '0') {
            $j(this).attr("action", "<?php bloginfo('url'); ?>/confirmation-2");
        }
    });
});
</script>

Any help will be highly appreciated.

Dipak G.
  • 715
  • 1
  • 4
  • 18
  • This looks like a programming question. It might fit better on [so]. – Donald Duck May 24 '18 at 16:09
  • @DonaldDuck Thanks. How could I make such a silly mistake? Do you know how can I migrate this question to Stack Overflow? – Dipak G. May 24 '18 at 16:17
  • _“Don't see any JavaScript errors in browser console”_ - you often don’t, when the browser immediately submits the form and reloads the page. Check the options to see if IE/Edge offer to keep console contents after loading a new page, as other browsers do. Next, I’d check if this wasn’t an [attr vs prop](https://stackoverflow.com/questions/5874652/prop-vs-attr) issue. And last but not least, I’d try to set `this.action = "..."` directly, and see if that changes anything. – CBroe May 25 '18 at 07:42

0 Answers0