Solved

Passing form variables between forms and to a different script file

Posted on 2000-04-15
8
186 Views
Last Modified: 2013-12-25
Hi, I have two separate forms. Both have different action URLs. The first form has a number of check boxes with different names and a text box. The second box has a text box too. If I checked some checkboxes in the first form and paste some texts in the second form and submit the second form to a different perl script file  the all names of all checked checkboxes and the text box variables should be accessed by the second file. Please help me how to pass these variables and how to get those variables in the second file.
Both forms are in a same page. Each one has a submit butten. The first form's action URL is self scripting. That is, it calls the  same script where the forms are located. But the second form's action URL is different.
-knesan
0
Comment
Question by:knesan
8 Comments
 
LVL 1

Expert Comment

by:lambda
ID: 2720737
U will get the values of the first form as

document.form1Name.check1.value,
document.form1Name.check2.value,
....
document.form1Name.txt1.value,
etc.

In the onSubmit () of the second form,
pass these as hidden.

function subThis ()
{
  document.form2Name.checkA1.value = document.form1Name.check1.value;
// like wise for all values in form1.

  return true;
}


<form name="form2Name" method="post" action="/cgi-bin/something.cgi" onSubmit="return subThis()">
<input type="hidden" name="checkA1">
<input type="hidden" name="checkA2">
<input type="hidden" name="txtA2">
..
..
</form>


HTH.
£.
0
 

Expert Comment

by:venky75
ID: 2721560
Hi there,

Can u elaborate a little bit as to whether both  the forms are located on different pages or if on same page are u using one submit button for each of the forms.

Bye
venky
0
 

Author Comment

by:knesan
ID: 2722794
Edited text of question.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 1

Expert Comment

by:lambda
ID: 2725268
Did you try the code I had given?

£.
0
 

Author Comment

by:knesan
ID: 2726743
Hi lambda,
I guess your code is in Java script. Am I write? But my rest of the code is in perl. Can you please give me a sample code in perl? Or Can I use this java script in my perl script?
thanks..
knesan
0
 
LVL 1

Expert Comment

by:lambda
ID: 2729350
U can give this Javascript code in ur html page. That is the only way u can get the values in a different form.

£.
0
 

Expert Comment

by:rickhall2000
ID: 2731307
The only way I have found to do this is with JavaScript.  As Lambda said you can put the javascript into the html of the page.  If you are generating the html with perl then you can get a bit trickier and have the Perl write out the Javascript to put in the page.  For example if you wanted to put Lambda's script in your page, part of which was this:

function subThis ()
                    {
                      document.form2Name.checkA1.value = document.form1Name.check1.value;
                      return true;
                    }

you would do it in perl with:

print "function subThis()\n";
print "{\n";
print "doctument.form2Name.checkA1.value = document.form1Name.check1.value;\n";
print "return true;\n";
print "}\n";

I think you get the idea.  The only part where it can get a bit tiresome is remembering which of the line breaks you want where, and what quotes you want where.  Best thing to do is to write the javascript by itself, then adjust it so that Perl will print it accordingly.  Anywhere the javascript calls for a \n you will have to replace it with \\n.  Anywhere the javascrip uses a double quote, you will have to replace it with \".  the ends of your lines may look strange with things like \");\n"; for text within a function call, the semicolon for the javascript the new line character the close quote for the Perl and the required semicolon for the perl, but as long as you pay attention to the details it is not difficult.
0
 

Accepted Solution

by:
HedgeMaze earned 50 total points
ID: 2740604
Is the user required to fill out both forms?

Here's one possibility:

Have the user fill out the first form when submit is clicked and the first script runs have the first script (script1) generate the html codes for the second form which is processed on submit by the second script (script2).  Then input the variables that you want to pass between the forms as hidden variables within the HTML form.

Something like the line below:

print "<input type=\"hidden\" name=\"id\" value=\"$num\">\n";

name is the name of the variable as used by script2 and the value represents the information (variable) processed by script1.

I use this quite a bit for a game I'm working on.  It's probably the best way to do this without resorting to JavaScript.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

820 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