Change onclick action with a Javascript function

前端 未结 8 1374
刺人心
刺人心 2020-12-02 12:14

I have a button:


When I click this button the first time, I want it to exe

8条回答
  •  独厮守ぢ
    2020-12-02 12:38

    For anyone, like me, trying to set a query string on the action and wondering why it's not working-

    You cannot set a query string for a GET form submission, but I have found you can for a POST.

    For a GET submission you must set the values in hidden inputs e.g.

    an action of: "/handleformsubmission?foo=bar" would have be added as the hidden field like:

    This can be done add dynamically in JavaScript as (where clickedButton is the submitted button that was clicked:

    var form = clickedButton.form;
    var hidden = document.createElement("input");
    hidden.setAttribute("type", "hidden");
    hidden.setAttribute("name", "foo");
    hidden.setAttribute("value", "bar");
    form.appendChild(hidden);
    

    See this question for more info submitting a GET form with query string params and hidden params disappear

提交回复
热议问题