Link to home
Start Free TrialLog in
Avatar of knesan
knesan

asked on

Passing form variables between forms and to a different script file

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
Avatar of lambda
lambda

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.
£.
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
Avatar of knesan

ASKER

Edited text of question.
Did you try the code I had given?

£.
Avatar of knesan

ASKER

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
U can give this Javascript code in ur html page. That is the only way u can get the values in a different form.

£.
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.
ASKER CERTIFIED SOLUTION
Avatar of HedgeMaze
HedgeMaze

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