[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

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
0
tcbarker4
Asked:
tcbarker4
1 Solution
 
netsmithcentralCommented:
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>
0
 
b0lsc0ttCommented:
You don't need quotes around a variable in Javascript.  However you do have an issue and can simplify what is happening on page 2.  There is no reason for Javascript on that page.

If page2 is also an ASP page then use ...

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

That will have the ASP script fill the hidden form values on page2 with the info you want to send to page 3.

Let me know if you have a question or need more info.

bol
0
 
mr_egyptianCommented:
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 %>">
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
b0lsc0ttCommented:
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
0
 
b0lsc0ttCommented:
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
0
 
tcbarker4Author Commented:
Thanks bol. That worked perfectly.
0
 
b0lsc0ttCommented:
Great.  Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now