Solved

Passing form variables between forms and to a different script file

Posted on 2000-04-15
8
187 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
[X]
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
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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

752 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