How to post values of HTML form to new HTML page using javascript - Stack Overflow

I have a HTML form on 'page1.html' with four elements (textbox1, textbox2, listbox1, listbox2

I have a HTML form on 'page1.html' with four elements (textbox1, textbox2, listbox1, listbox2). on clicking submit, i want the values of these elements to be posted in table to new page (page2.html)

Table in page 2 is as follows:

  • First row : value of textbox1
  • Second row column 1: value of textbox2
  • Second row column 2: value of listbox1
  • Third row: value of listbox2

Please help

I have a HTML form on 'page1.html' with four elements (textbox1, textbox2, listbox1, listbox2). on clicking submit, i want the values of these elements to be posted in table to new page (page2.html)

Table in page 2 is as follows:

  • First row : value of textbox1
  • Second row column 1: value of textbox2
  • Second row column 2: value of listbox1
  • Third row: value of listbox2

Please help

Share Improve this question edited Jan 20, 2013 at 10:13 user1994366 asked Jan 20, 2013 at 10:10 user1994366user1994366 431 silver badge4 bronze badges 4
  • Which server-side language are you using? Do you want to do all this in js only? – Wolf Commented Jan 20, 2013 at 10:14
  • 1 The only way that you can acplish that is either, pass those values as a query string or stored it in a database so it can be persisted when going to the other page. Or even cookie in a desperation attempt.. – Dennis Rongo Commented Jan 20, 2013 at 10:14
  • looking for a javascript solution only. or can i have the table hidden in same page and post values to table after submit? – user1994366 Commented Jan 20, 2013 at 10:18
  • Ok. In that case you can try my answer. – Wolf Commented Jan 20, 2013 at 10:27
Add a ment  | 

2 Answers 2

Reset to default 3

With plain html and javascript you can do like this

page1.html

<input type="text" id="txt1" />
<input type="button" value="Submit" onclick="postData()" />

javascript

function postData(){
    var val = document.getElementById("txt1").value;

    var tbl = "<table><tr><td>"+val+"</td></tr></table>";

    var w = window.open("page2.html");

    w.document.write(tbl);
}

Here You can use a form with type = GET and action="page2.html"

Then in page2.html, in pageload use the following function to extract the URL parameters

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}

Demo:

Page1.html

<form type="GET" action="page2.html">
<input name="text" id="txt" />
</form>

Page2.html

<script>
function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}
alert(getURLParameter("text"));
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744238298a4564579.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信