Solved

Adding multiple search buttons to a form

Posted on 2002-05-07
4
136 Views
Last Modified: 2013-12-24
I want to create a search page in which the user adds an input field.  If he clicks one button a certain results1.cfm page is retrieved, if he hits another an alternate results2.cfm page is retrieved.  How do I go about this?

I'm guessing that I have to use an 'if' statement based on the button he clicks, i.e. if he clicks button1 action=results1.cfm, if he clicks button2 action=results2.cfm.

Is this possible?
0
Comment
Question by:CTerreri
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Scott Bennett
ID: 6995195
I would have both submit buttons go to the same action page then include the results page based on wich button was pushed.

Example:
____________________________________________
ActionPage.cfm
--------------------------------------------
<cfif isDefined("Form.Button1")>
    <cfinclude template="results1.cfm">
<cfelseif isDefined("Form.Button2")>
    <cfinclude template="results2.cfm>
</cfif>
____________________________________________
Form.cfm
--------------------------------------------

<cfform name="MyForm" action="ActionPage.cfm" method="POST">
<cfinput type="text" name="Input1">
<input type="Submit" name="Button1" value="Button1">
<input type="Submit" name="Button2" value="Button2">
</cfform>
_______________________________________________

Although another possibility is to create a hidden form and use java script to copy the information to the hidden form to the alertnative action page.
Like this:

-----------------------------------------------------
<script language="JavaScript">
function proccessform2()
{
     var Input1 = document.MyForm.Input1;
     document.MyHiddenForm.Input1.value = Input1;
     document.MyHiddenForm.submit();
}
</script>


<cfform name="MyForm" action="results1.cfm" method="POST">
<cfinput type="text" name="Input1" value="">
<input type="Submit" name="Button1" value="Button1">
<input type="Button" onclick="proccessform2();" name="Button2" value="Button2">
</cfform>

<cfform name="MyHiddenForm" action="results2.cfm" method="POST">
<input type="hidden" name="Input1" value="">
</cfform>

---------------------------------------------------------
0
 
LVL 5

Expert Comment

by:nathans
ID: 7001888
There is two ways to do this..

1. JavaScript can change which page it submits too depending on which button you press.

2. You can send the page to a ColdFusion page that then forwards to whichever page you want it to go to.


Nathan
http://www.cftipsplus.com
0
 
LVL 14

Accepted Solution

by:
Scott Bennett earned 100 total points
ID: 7001942
Yes, that is exactly what I already suggested, just without the examples. =)
0
 

Author Comment

by:CTerreri
ID: 7002573
I went ahead and tried the "forwarding" to an intermediate action_page and and it worked fine.

Thanks for the help!!!!!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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