0

I have developed the following function to open an email with the html form contents in the body and also redirect the web page to a "Thank You" page. My problem is, window.location.href will only read once (whichever the last call is) and ignore the first one. If I change one to window.open(), the function works but then I have a new page open and my task is to not have a new browser page open.

I have tried to next functions and setTimeout(function()) to no avail. I probably did not implement them correctly though.

Here is where I call the function in my html:

<input class="buttonRequest" type="submit" value="Submit Request" onclick="OnButton1(); return false">

Here is my Javascript:

function OnButton1() {

   var email = "mailto:emailAddress@email.com"
      + "&subject=" + "Access Request"
      + "&body=" + $("#userName").val()
      + $("#user-email").val()
      + $("#ID").val()
      + $("#command").val()
      + $("#orgCode").val()
      + $("#selectStyle").val();

    var newPage = "ThankYou.html";

    window.location.href = newPage;
    window.location.href = email;
}
  • What is the desired behavior here? You obviously can only redirect once, since you then are on another page. Do you want to redirect to the one page and then after like 10 seconds to another? – Patrick Hollweck Aug 28 '18 at 18:18
  • @PatrickHollweck The end goal is after the form is filled out, the user presses the submit button where a email is opened with the contents of the form and the webpage redirects to the "Thank you" page. I know with html, you can only have one action on a form but I thought javascript allowed for more actions? – beginnerDeveloper Aug 28 '18 at 18:22
  • See the `setInterval` implementation in [this question](https://stackoverflow.com/questions/31709893/two-urls-in-function-using-window-location-href)'s accepted answer. Looks similar to what you are trying to accomplish – brae Aug 28 '18 at 18:24
  • @brae I tried it again and it worked! I must have made an error the first time I tried it. Thank you! – beginnerDeveloper Aug 28 '18 at 18:31

0 Answers0