Link to home
Start Free TrialLog in
Avatar of tcbarker4
tcbarker4

asked on

Passing variables from one form to another to a third form

I have 3 forms and am trying to pass the contents of field 1 and field 2 on form1.htm to the third form. I am able to pass the variables from form1.htm to form2.asp via the following code inserted above the <html> tag:

strLicensePlateNr = Request.form("LicensePlateNr")
strLicensePlateSt = Request.form("LicensePlateSt")

If I do the following:

response.write strLicensePlateNr
response.write strLicensePlateSt

then the contents of those two variables are displayed.

Where I am running into issues is now trying to pass them from form2.asp to form3.asp.

I have the following code in form2.asp:

<script language="JavaScript" type="text/javascript">
 function validate(form) {
 
  document.FrontPage_Form1.strPlate.value=strLicensePlateNr;
  document.FrontPage_Form1.strState.value=strLicensePlateSt;
 }
</script>

and

      <input type="submit" onClick="javascript:return validate(this)" value="Continue to Incident Reporting" name="B1"></p>
      <input type="hidden" name="strPlate" value="">
      <input type="hidden" name="strState" value="">

the purpose of this is trying to pass the variables onto form3.asp

In form3.asp, I have the following code inserted above the <html> tag:

strLicensePlateNr = Request.form("strPlate")
strLicensePlateSt = Request.form("strState")

but when I try and display the variables on form3.asp with the following code:

<%
response.write strLicensePlateNr
response.write strLicensePlateSt
%>

I get nothing. I might be mixing client-side and server-side scripts. So my question is........

How do I pass the variables from form1.htm to form2.asp to form3.asp ???

Thanks for your help

Tim
Avatar of netsmithcentral
netsmithcentral
Flag of United States of America image

You need to put quotes around string variables in javascript.

<script language="JavaScript" type="text/javascript">
 function validate(form) {
 
  document.FrontPage_Form1.strPlate.value= 'strLicensePlateNr';
  document.FrontPage_Form1.strState.value= 'strLicensePlateSt';
 }
</script>
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

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
Look into sessions.  Much simpler than populating hidden fields.  I'm  not much on asp, but here's a tutorial:

http://www.w3schools.com/asp/asp_sessions.asp

If you really want to do it the other way, in page 2 try something more like this:

      <input type="submit" onClick="javascript:return validate(this)" value="Continue to Incident Reporting" name="B1"></p>
      <input type="hidden" name="strPlate" value="<% response.write strLicensePlateNr %>">
      <input type="hidden" name="strState" value="<% response.write strLicensePlateSt %>">
By the way, in Javascript quotes would be used if the value was a string.  Since the variable is an ASP one then the result would be a string (in the code the browser sees).  However for the ASP variable to be used the ASP code would need to be ...

<script language="JavaScript" type="text/javascript">
 function validate(form) {
 
  document.FrontPage_Form1.strPlate.value='<%= strLicensePlateNr %>';
  document.FrontPage_Form1.strState.value='<%= strLicensePlateSt %>';
 }
</script>

There is no reason for this though if you use my suggestion because the form will already have the values as part of the html.  If Javascript were disabled this would still work.

bol
Sessions are nice and have a great use but if you already have a form and fields on page2 going to page3 then there is no reason to use a Session.  Sessions do have the downside of requiring a cookie to work and in some rare cases that might be disabled by the browser or user.  In that case the session would not work.

Sessions are good to know though and, if you have a question about them in ASP, we can help in a new question in the ASP zone.

bol
Avatar of tcbarker4
tcbarker4

ASKER

Thanks bol. That worked perfectly.
Great.  Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol