Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form variables not passed to action page - please help!

Status
Not open for further replies.

ColdFusionKing

Programmer
Dec 5, 2002
145
0
0
GB
Hi Guys,
Am really hoping for someone to help me. I have this problem and can't find a solution. I have a form with two buttons with an onClick event each. Each button calls a javascript function. When the user clicks on the button, I'm assigning all form field values to hidden variables. When I dump the form values on the action page,
I see the form field values (including hidden form field values) for button 1, but don't see the same when button 2 is clicked. Here is my code

<script LANGUAGE=&quot;javascript&quot;>

function rentSubmit()
{
with (document.the_form) {
FirstName_hid.value = FirstName.value;
LastName_hid.value = LastName.value;
}
document.the_form.action = &quot;RentalForm.cfm&quot;;
document.the_form.submit();
}

function orderSubmit()
{
with (document.the_form) {
FirstName_hid.value = FirstName.value;
LastName_hid.value = LastName.value;
}
document.the_form.action = &quot;OrderForm.cfm&quot;;
document.the_form.submit();
}

</script>

<form name=&quot;the_form&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;FirstName&quot; id=&quot;FirstName&quot; value=&quot;&quot; size=&quot;56&quot;><br>
<input type=&quot;text&quot; name=&quot;LastName&quot; id=&quot;LastName&quot; value=&quot;&quot; size=&quot;56&quot;>

<input type=&quot;hidden&quot; name=&quot;FirstName_hid&quot; value=&quot;&quot;>
<input type=&quot;hidden&quot; name=&quot;LastName_hid&quot; value=&quot;&quot;>

<input type=&quot;button&quot; name=&quot;Rent&quot; value=&quot;Rental Form&quot; onclick=&quot;rentSubmit()&quot;>
<input type=&quot;button&quot; name=&quot;Order&quot; value=&quot;Order Form&quot; onclick=&quot;orderSubmit()&quot;>
</form>

When I click on the &quot;Rent&quot; button, I am taken to RentalForm.cfm. In this file, I have a
<cfdump var=&quot;#form#&quot;>
It dumps all the form variables as I expect it to. But when I click on the &quot;Order&quot; button, I get directed to OrderForm.cfm but the cfdump on that page displays nothing. I don't understand why I don't see the form variables? Can somebody show/tell me how to fix this problem.

Many Thanks,
Allan
 
I would recommend you to do it without javascript.

Here is how you do it:

1) remove all javascript
2) in main file put: <form name=&quot;the_form&quot; method=&quot;post&quot; action=&quot;resolveform.cfm&quot;>
3) buttons:
<input type=&quot;submit&quot; name=&quot;action&quot; value=&quot;Rental Form&quot;>
<input type=&quot;submit&quot; name=&quot;action&quot; value=&quot;Order Form&quot;>

4) create file resolveform.cfm:
<cfif Form.action EQ &quot;Rental Form&quot;>
<cfinclude template=&quot;RentalForm.cfm&quot;>
<cfelseif Form.action EQ &quot;Order Form&quot;>
<cfinclude template=&quot;OrderForm.cfm&quot;>
</cfif>

I think this (or similar) way is much better than to use Javascript

Alex
 
Many Thanks Alex for your advice, I have implemented your solution and it all works.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top