Reputation:
How do I create a form that can submit a value to another page and then print it out without using any server-side code from a programming language?
i.e. First.html
<form method="get" action="Second.html">
<input type="text" name="myname" />
<input type="submit" value="submit" />
</form>
Second.html
<p>input.myname</p>
Upvotes: 0
Views: 1702
Reputation: 429
You want to transfer data from one page to another without using a server-side code ? That's extremely unrecommended, it can be used using javascript like Justin said, I'd recommend you ASP.NET and passing with QueryString
or Session
as you can see in here.
Upvotes: 0
Reputation: 19016
I don't know why you want to do it that way, and actually i don't see any advantage.
Anyway, in second.html, you could use javascript (jquery framework for example) to parse query string and get your value back.
first.html
<html>
<head>
</head>
<body>
<form method="GET" action="second.html">
<input type="text" name="myname" />
<input type="submit" value="click me" />
</form>
</body>
</html>
And then, in your second.html, use this:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript">
(function($) {
$.QueryString = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'))
})(jQuery);
</script>
</head>
<body>
<script type="text/javascript">
alert('Test: ' + $.QueryString["myname"]);
</script>
</body>
</html>
Upvotes: 1