Search action

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

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/

Re: [Jason] Search action

By Toledoh - November 3, 2010

Perfect! Thanks yet again!
Cheers,

Tim (toledoh.com.au)