Two forms - one submit button?

烈酒焚心 提交于 2019-12-10 11:55:50

问题


I have TWO forms on my website.

Is it possible when I submit one of these, it will take form data from a particular field in the other form?

I am using the Recurly system with PHP.


回答1:


You can write your own function.

function submit (){
   document.getElementById("firstform").submit();
   document.getElementById("secondform").submit();
}

You can then make a button that calls this function.

If this doesn't work, try again using ajax. Example




回答2:


You can do it with javascript.

For example:

var request =false;

function submit()
{
    var yourobject = document.getElementById("yourobject").value;

    data = "yourobject" + "=" + encodeURIComponent(yourobject);

    request.open("POST", "yourpage.php", true);
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    request.send(data);
}

And the input:

<input type="button" onclick="submit()" value="Submit" />


来源:https://stackoverflow.com/questions/19785198/two-forms-one-submit-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!