[OT] CGI - web site help

Andre Garzia soapdog at mac.com
Fri Apr 27 11:19:08 EDT 2007


Sarah,

it is not difficult to do that, but requires some javascript.

What you need is to create a mouseUp handler for those radio buttons.  
When that handler triggers, it uses an asynchronous request to talk  
to the server and update the results. I'll do a little snippet below  
that may help.

Instead of creating everything from scratch, I'd advise you to use  
the "Javascript Prototype Library", you include it in your pages with  
(pointing to the correct url of course):

		<script type="text/javascript" src="/js/prototype.js" ></script>

Then you need to create your own handler to go back to the server and  
fetch the results, if your results are placed in a container such as  
a DIV with id="searchResults" then you can simply create an AJAX  
updater, this updater, queries a server CGI that returns a simple  
HTML chunk, this chunk is inserted in a place you choose. For  
creating such thing to update a div with id="searchResults" we do:

<script type="text/javascript">
	function updateDiscount()

	document.getElementById("searchResults").innerHTML=""
	
	var formData = "q=" + str;
	var myAjax = new Ajax.Updater(
		'searchResults',
		'/cgi-bin/search.cgi',
		{
						method: 'get',
						parameters: formData
					});
}
</script>

See that this script will not work, but it is a simple thing to  
explain, first you will need to loop your radio buttons fetching  
their values to assemble a URL that you can post to your search CGI.  
You can use:

	document.getElementById("theID").value

to retrieve the value of an element naming it by its ID. Then after  
getting all the needed radio buttons, you can simply assemble the URL  
using plain string concatenation routines such as:

	var formData = "r1=" + value1 + "&r2=" + value2;

then you instantiate your ajax updater passing to it the ID of the  
element whose contents will be updated, you also pass the URL of the  
CGI to be called, and last, you pass a keyed list (Actually I think  
that is an object), the minimum elements for this list are the method  
and the parameters for the call. Like:

	var myAjax = new Ajax.Updater(
		'searchResults',
		'/cgi-bin/search.cgi',
		{
						method: 'get',
						parameters: formData
					});

This takes care of creating your routines, what you need is to bind  
the radio buttons to your routine, in our case the routine name is  
updateDiscount, so it would look like:

		<input type="radio" id="radio1" onmouseup="updateDiscount()" />

It's easier done than explained. You can fetch RevHTTP <http:// 
andregarzia.com/RevHTTP.zip"> and see the ajax examples.

Cheers
andre




On Apr 27, 2007, at 6:01 AM, Sarah Reichelt wrote:

> On 4/27/07, Bernard Devlin <revolution at knowledgeworks.plus.com> wrote:
>> > a set of radio
>> > buttons that alter the search results. Unfortunately, changing  
>> these
>> > requires doing a new search before the new options are displayed.
>> >
>> > So my question is: is there any way to detect the radio buttons  
>> so the
>> > options can be displayed dynamically?
>>
>> Hi Sarah,
>>
>> I'm not really clear what are the limitations which you are trying to
>> overcome.  Do you mean that the radio buttons do something like to
>> the search results e.g. change the sort order of the search results,
>> or that they filter the search results in some way?  By "before the
>> new options are displayed" do you mean "before the choice takes  
>> effect"?
>
> Basically, the search finds matching products in a catalog. The radio
> buttons allow you to show the list price or various discounts. The
> problem is when the user selects a radio button but doesn't click
> "Search" again. It looks as if a discounted price is being displayed,
> but it really isn't.
>
> Sarah
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list