Solved

Passing form variables between forms and to a different script file

Posted on 2000-04-15
8
181 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
Comment Utility
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
Comment Utility
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
Comment Utility
Edited text of question.
0
 
LVL 1

Expert Comment

by:lambda
Comment Utility
Did you try the code I had given?

£.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:knesan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
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 …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

772 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

13 Experts available now in Live!

Get 1:1 Help Now