Link to home
Start Free TrialLog in
Avatar of margarit
margaritFlag for Israel

asked on

How to pass parameters between pages/forms in HTML?

Hello,

I am new to HTML.
I have a page, on this page I have a form with button. when I click the button another form opens (from another page). I need to pass a parameter to this form when it opens. Is it possible?
If yes, how to do it?

THANKS
Margarit
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

yes you can pass the parameters by using as cgi variables, form variables and so on
 
take a look at this post
http://www.webdeveloper.com/forum/archive/index.php/t-2533.html
Avatar of Shaun Kline
There are a number of ways. One would be to have a hidden field (input type="hidden") and put your parameter into this field. A second way would be to alter the action property of the form tag to include the parameter as part of the query string (<page>?<parameter key word>=<parameter value>.

If you need to determine what that parameter value should be based on what the user entered, then you are looking at using javascript to handle setting the hidden field value/changing the action property.
ASKER CERTIFIED SOLUTION
Avatar of xBellox
xBellox

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SimpleJ
SimpleJ

to make this simple do the following:

<form name="input" action="second_page.html" method="get">
Username:
<input type="text" name="user" />
<input type="submit" value="Submit" />
</form>

so the second_page will open in browser as:
 http://<some_host>/second_page.html?user=WhateverYouTyped

so there you go, you have passed a parameter value to next page.

However, the easiest way to get this parameter to page content is for example with php:
1. rename second_page.html to second_page.php
2. in second_page.php file type: <?php echo "I typed:" . $_request['user']; ?>

You can ofcourse use other methods (with aspx, jsp, js,....)

If you`re new to html then I suppose you haven`t tried any server side lang. either.
Just to get you started:
- install wamp server : http://www.wampserver.com/en/
- rename all *.html files to *.php
- copy *.php files to wamp www destination
- in browser type http://localhost/first_file.html

correction:
in browser type http://localhost/first_file.php
@SimpleJ:

  It isn't php language, it's pure HTML. Just renaming files may not work if the server was not correctly configured.
Avatar of margarit

ASKER

Hello,
Thanks for so many helpful comments.
I am already using Java script.
My page2 should get a parameter from page1 but later it should pass back to page1 a list of parameters. So what action should I set : "set" or "get"?
How to implement it?
THANKS
The method to pass parameters from one simple HTML doc to another is always GET.

The "action" is the file that will receive the parameters.

So the page1.html, must has the form like this:

<form name='frm1'  action='page2.html' method='get'>


And page2 like this:

<form name='frm2'  action='page1.html' method='get'>
THANKS!
I will try it now
Hello,
I tried the xBellox solution, but the problem that in my DestPage I get nothing. If I print "query"  it is empty. Why?
Hi, At first I had a problem but then I defined a button as "submit " and it works.