Search action

3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 3, 2010   (RSS)

By Toledoh - November 3, 2010

Hi Guys,

I've got a Real Estate site that I want to display results by a table view, a thumbnails view or a map view.

The viewers are resultsList.php, resultsThumb.php and resultsMap.php.

I want the search function to request the user how they would want the results displayed. ie.
<form method="POST" action="resultsMap.php">
Display:
<p>
<label>
<input type="radio" name="View" value="list" id="View_0">
list</label>
<br>
<label>
<input type="radio" name="View" value="thumb" id="View_1">
thumb</label>
<br>
<label>
<input type="radio" name="View" value="map" id="View_2">
map</label>
<br>
</p>


How can I get the action="resultsMap.php" to reflect the choice made in the form rather than hard coded to resultsMap.php?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Search action

By Jason - November 3, 2010

Hi Tim,

You can do this with a javascript function. First you can set up your form like this:

<form method="POST" name ="displayForm" action="resultsMap.php" >
Display:
<p>
<label>
<input type="radio" name="View" value="resultsList.php" onchange="formAction(this);" >
list</label>
<br>
<label>
<input type="radio" name="View" value="resultsThumb.php" onchange="formAction(this);" >
thumb</label>
<br>
<label>
<input type="radio" name="View" value="resultsMap.php" onchange="formAction(this);" >
map</label>
<br>
</p>


The value of each radio button is the page we want it to submit to.

Next, put this javascript code between the <head></head> tags on your page:

<script type="text/javascript">
function formAction(radio){
if(radio.checked){
document.displayForm.action=radio.value;
}
}
</script>


This code will change the action of the form to the value of the selected radio button. NOTE: it is important that you give the form the name "displayForm". If you use another name, you'll need to change that name in the javascript as well. Also, this form will default to whatever is originally in the "action" attribute if no radio button is selected.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/