Solved

Passing form variables between forms and to a different script file

Posted on 2000-04-15
8
182 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
 
LVL 1

Expert Comment

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

£.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
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 dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now