0

i have following HTML

<Html>
<head>

</head>
<body>
<form action="Page2.html" method="get"/>
    <h1>Hello</h1>

    <input name="fname"/>
    <input type="submit" value="submit" />
</body>
</html>

when i click submit button page is redirect to Page2.html with querystring of fname now how to retrieve the querystring value in page2.html page ???

and if i use POST method , how to retrieve post data method ??

Thanks..

ghanshyam.mirani
  • 3,075
  • 11
  • 45
  • 85
  • 1
    you'd need to use a server side scripting language of some kind, AFAIK there isn't any way to use GET and POST variables in HTML alone. I'd suggest PHP http://php.net – totallyNotLizards Oct 22 '13 at 09:29
  • Duplicate of http://stackoverflow.com/questions/10896854/simple-html-post-without-any-server-scripting-can-be-done-using-js – James Jithin Oct 22 '13 at 09:40

5 Answers5

1

first, to retrieve a get parameter with javascript, use the following function in Page2.html:

function get_query_param(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

usage:

var fname = get_query_param('fname');

secondly,

about retrieving post parameters, it's impossible with client-side implementation only.

for this, my friend, you will need some server side implementation (like php / asp.net / django / etc...).

post request are generally used to post some values from the client to the server, for example contact forms.

think about it, get is for getting / reading / viewing.

post is for writing / storing.

hope that helps.

geevee
  • 5,411
  • 5
  • 30
  • 48
0

You will need to use a little scripting(PHP/JS) in your other page. In PHP you can use functions $_GET[] and $_POST[] to obtain GET/POST variable values.

Aakash
  • 1,860
  • 19
  • 30
0

Well, i think best way to get parameters from html is using php with variable

$_GET['name'] or $_POST['name'].

If you use post method wou will not be abloe to see data in html, but if you are interested in using just javascript and html you can look at this using GET method from your form here

0

You want to retrieve value by get or post then you need to do server side codding in J2ee then retrieve values.

For tutorial J2EE

Prateek
  • 6,785
  • 2
  • 24
  • 37
-1

You can not retrieve value in .html page for that you need to set .php or .asp or any other scripting language page.

like below.

<Html>
<head>

</head>
<body>
<form action="Page2.php" method="get"/>
    <h1>Hello</h1>

    <input type="text" name="fname" value = 'Name_name'/>
    <input type="submit" value="submit" />
</body>
</html>

Page: Page2.php

 <?php
    echo $_GET['fname']; // output : Name_name
    ?>
w3b
  • 823
  • 6
  • 14
  • 1
    Wrong. `POST` data cannot be accessed on the client side but `GET` data passed in the query string can be accessed with JavaScript. – Sébastien Oct 22 '13 at 09:36
  • please check out method of form its get – w3b Oct 22 '13 at 09:36
  • Check yourself first "You can not retrieve value in .html page for that you need to set .php or .asp or any other scripting language page." That's **wrong**. – Sébastien Oct 22 '13 at 09:38