AjaxMadeSimple - onClick event

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
JayDee
Forum Members
Forum Members
Posts: 13
Joined: Tue Oct 09, 2007 4:21 pm

AjaxMadeSimple - onClick event

Post by JayDee »

Hi guys,

On my website i have a banner which now changes as you reload the page.
I would like a add a button 'Shuffle' and make a random image appear, via Ajax. I have started this imagemodule and made something working. However, when i click the 'shuffle' button, i'm not getting 1 new image, the image keep changing untill i press esc.

How my module looks like now: (btw, 'foto' is dutch for 'picture')

BannerFoto.module.php
  • Containts a function init()
    Checks for pictures in a directory and generates an (shuffled) array in $_SESSION['fotos']
  • Contains a function MaakFoto()
    Picks a random image from session and echoes html:
action.default.php
  • Checks whether $_SESSION['fotos'] is set. If not run $this->init()
  • Run $this->MaakFoto();, this displays the photo on page acces
  • Register Ajax requester:
    $ajax->RegisterAjaxRequester($this->GetName(), 'bnnr','fpbanner','MaakFoto',false,array(), array(),-1);
From a the session(['ajaxmsgeneratedcode']) i found the javascript function makeBannerFotosbnnrRequest().

I call these functions from a content page, using

Code: Select all

<div id="fpbanner">
{cms_module module="BannerFotos"}
</div>
<span onClick="return makeBannerFotosbnnrRequest();">Klik!
</span>
Unfortunately clicking the shufflelink does not replace the content of my div.fpbanner once, it keeps picking a random image (function MaakFoto)

Code: Select all

function makeBannerFotosbnnrRequest() {
  var http_request=gethttp();
  http_request.onreadystatechange = function() { alertBannerFotosbnnr(http_request,true); };
  http_request.open('GET', 'http://www.nsrvphocas.nl/modules/AjaxMadeSimple/requesthandler.php?module=BannerFotos&method=MaakFoto&', true);
  http_request.send(null);
}
Does anyone have some experience on this subject?
Last edited by JayDee on Sun Nov 18, 2007 1:54 pm, edited 1 time in total.
User avatar
Silmarillion
Dev Team Member
Dev Team Member
Posts: 483
Joined: Sun Jan 02, 2005 9:10 pm
Location: Denmark

Re: AjaxMadeSimple - onClick event

Post by Silmarillion »

Hi JayDee

I take it you did a form with a submit button which includes the ajax-code, something like:
GetFormOnSubmit($this->GetName(),"bnnr").'>


Could I see your whole module? I am very interested as I actually considered doing some kid of AjaxMS-driven gallery myself, but never got around to it...

Regards
Morten/Silmarillion
JayDee
Forum Members
Forum Members
Posts: 13
Joined: Tue Oct 09, 2007 4:21 pm

Re: AjaxMadeSimple - onClick event

Post by JayDee »

No, i don't want my page to have a submit button. I want a onclick event on a <a, <span or <div (or any html object of choice).

From the $_SESSION variable i found a Javascript function makeBannerFotosbnnrRequest(); I tought using this as an onclick event would do the trick. It does, but it keeps doing it...

I'll attach the XML of my module so far. There is no admin function so you'll have to set the image directory in the source.
Create a content page containing the following code (enter via HTML source view)

Code: Select all

<!-- This is the image -->
<div id="fpbanner">{cms_module module="BannerFotos"</div>

<!-- This is the button to change the picture -->
<span onmousedown="return makeBannerFotosbnnrRequest();">Klik!</span>

<!-- Echos the Javascript, could not found out why the continues updates happen though -->
<pre>{php}echo $_SESSION['ajaxmsgeneratedcode'];{/php}</pre>
And a example: http://www.nsrvphocas.nl/?page=testing
Attachments

[The extension xml has been deactivated and can no longer be displayed.]

Last edited by JayDee on Mon Nov 19, 2007 9:43 pm, edited 1 time in total.
Locked

Return to “Modules/Add-Ons”