0

I am looking using jquery/javascript for a way to re-direct users to a different url after the form action has been performed. It calls an appscript url that writes to a google spreadsheet. What I'd like is to redirect the users to a specific url that I chose. E.g. https://www.google.com or like. Below is my form:

<form action="https://script.google.com/macros/s/AKfycbwg0ASXLu-2awVG_F02o5S1u1pUyrYNHaAQvxzrObFj-47vFE8/exec"
                  id="courses" method="post" name="courses">
                    <h4>
                      Content Survey
                    </h4>
                    <fieldset>
                      <legend><span class="number">1</span> Module Info</legend> <input name=
                      "name" type="hidden" value="module1"> <input name="product"
                      type="hidden" value="XXX"> <label>Select which module you wish to
                      rate:</label> <select id="courses" name="clearness">
                        <option value="extremely_clear">
                          5: Extremely clear
                        </option>
                        <option value="moderately_clear">
                          4: Moderately clear
                        </option>
                        <option value="clear_nor_unclear">
                          3: Neither clear, nor unclear
                        </option>
                        <option value="moderately_unclear">
                          2: Moderately unclear
                        </option>
                        <option value="extremely_unclear">
                          1: Extremely unclear
                        </option>
                      </select> <label>Please rate the clarity of the content:</label>
                    </fieldset>
                    <fieldset>
                      <legend><span class="number">2</span> Additional Info</legend> <label>Was
                      this module helpful?</label> <select id="courses" name="helpful">
                        <option value="yes">
                          Yes
                        </option>
                        <option value="no">
                          No
                        </option>
                      </select>
                    </fieldset><input type="submit" value="Apply">
                  </form>

I found this solution, but could not make it work. Anyone got any ideas on how I can approach this?

Regards.

Community
  • 1
  • 1
user2690151
  • 125
  • 2
  • 11

2 Answers2

0

One solution would be to use ajax to submit the form, then redirect users after. See the docs

Chris
  • 2,435
  • 6
  • 26
  • 49
0
var url = "https://script.google.com/macros/s/AKfycbwg0ASXLu-2awVG_F02o5S1u1pUyrYNHaAQvxzrObFj-47vFE8/exec";

$.fn.serializeArray= function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

var data = $("form").serializeArray();

var success = function() {
    window.location.href = "http://www.google.com";
}

$("input[type=submit]").click(function(e){
    $.post(url, data, success);
    e.preventDefault();
});

Reference serializeArray

Community
  • 1
  • 1
Z.Z.
  • 674
  • 6
  • 16
  • Thank you. I try to add the script after the end of the in its own – user2690151 Jan 28 '16 at 22:52
  • I forgot to add the click event to the submit button. Can you try the edited code? – Z.Z. Jan 28 '16 at 23:11
  • Z.Z. thank you so much. I tried it but no luck still: https://docs.google.com/document/d/1qqWRYhIVCpKHY9D2V9Dsu3tNxEUbM7Gc9ZnB_2BLxHs/edit – user2690151 Jan 29 '16 at 19:57