Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to pass parameters between pages/forms in HTML?

Posted on 2009-07-02
12
770 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:margarit
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24762634
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
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24762654
0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 24762659
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.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 9

Accepted Solution

by:
xBellox earned 500 total points
ID: 24762735
Yours source form has to use "GET" method

<form name='yourSrcForm' method='get' action='dest.html'>
<input type='text' name='testSrc' value='Hello'>
</form>

So, in your destiny html you have to use some javascript to read the params passed and set the params to your new form. Something like this:

<html>
<body>
 
<form name='yourFinalForm'>
<input type='text' name='testDest'>
</form>
 
 
<script language='javascript'>
 
// Getting all params passed and storing in qsParm array
var qsParm = new Array();
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
   var pos = parms[i].indexOf('=');
   if (pos > 0) {
       var key = parms[i].substring(0,pos);
       var val = parms[i].substring(pos+1);
       qsParm[key] = val;
    }
}
 
// Set the value to new form
document.yourFinalForm.testDest.value = qsParm['testSrc'];
 
</script>
</body>
</html>

Open in new window

0
 
LVL 1

Expert Comment

by:SimpleJ
ID: 24762781
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

0
 
LVL 1

Expert Comment

by:SimpleJ
ID: 24762799
correction:
in browser type http://localhost/first_file.php
0
 
LVL 9

Expert Comment

by:xBellox
ID: 24762874
@SimpleJ:

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

Author Comment

by:margarit
ID: 24763865
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
0
 
LVL 9

Expert Comment

by:xBellox
ID: 24763941
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'>
0
 

Author Comment

by:margarit
ID: 24764229
THANKS!
I will try it now
0
 

Author Comment

by:margarit
ID: 24776446
Hello,
I tried the xBellox solution, but the problem that in my DestPage I get nothing. If I print "query"  it is empty. Why?
0
 

Author Closing Comment

by:margarit
ID: 31599157
Hi, At first I had a problem but then I defined a button as "submit " and it works.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question