ryykko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-10 12:23 UTC
Newbie question : with return true and false in ajax.updater
hi guys
sry for my question; dont really know how to fix this
ve got a form to submit but return true everytime!!!
tx for help :)
<script type="text/javascript" language="javascript">
function disponibilitePseudo (idImg)
{
var pseudoToTest = $(''pseudo'').value;
imgPseudo = idImg;
if (pseudoToTest != "")
{
new Ajax.Updater(
''Pseudo'',
''check.php?pseudo=''+pseudoToTest+''&Date=''+escape(new
Date()),
{
method:''get'' ,
onComplete:
function succesRetourAjax (t)
{
if (t.responseText == "succes")
{
// Element.update("retourPseudo","available");
$(imgPseudo).src = ''good.gif'';
Element.hide("Pseudo");
return true;
}
else
{
Element.show("retourPseudo");
Element.update("Pseudo","Not available");
$(imgPseudo).src = ''wrong.gif'';
return false;
}
}
}
);
}
}
function checkForm()
{
return disponibilitePseudo(''imgPseudo'');
}
</script>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Jun-11 13:42 UTC
Re: Newbie question : with return true and false in ajax.updater
Returning from the callback functions of Ajax.Updater doesn''t actually
return the value to the scope that called the original function, as far
as I know. Your callback function has been called from within the
Ajax.Updater object and I suspect that you''re values are being returned
to methods of that object and not to where you want them to go. Off the
top of my head, you might be better off using the Event.observe()
function. You can then observe() the action of form submission and then
use Event.stop() to halt the submission rather than return false.
Something like this could work (emphasis on could, it''s a Monday and my
coffee''s not done):
Event.observe($("some_form_id"), "submit", function(event) {
/* ... prepare for Ajax here ... */
new Ajax.Updater("Pseudo", "check.php...", {
method: "get",
onComplete: function(t) {
if(t.responseText == "success") {
/* ... handle success ... */
} else {
/* ... handle failure ... */
Event.stop(event);
}
}
});
}
Using a closure, if I understand the term correctly, on the event
variable within your onComplete callback should halt further processing
of your event, just like returning false to an onsubmit event of a form
would do.
Also, I noticed when working on the above pseudo-code that you''ve named
your callback function; that''s a no-no. The callbacks are meant to be
either anonymous (i.e., without a name) or a specified function defined
elsewhere. You''ve tried to mix the two defining a function inline with
the Ajax.Updater options object but also giving them a name. This could
also be a problem for you.
- Dash -
ryykko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> hi guys
>
> sry for my question; dont really know how to fix this
>
> ve got a form to submit but return true everytime!!!
> tx for help :)
>
> <script type="text/javascript"
language="javascript">
> function disponibilitePseudo (idImg)
> {
> var pseudoToTest = $(''pseudo'').value;
> imgPseudo = idImg;
>
> if (pseudoToTest != "")
> {
>
> new Ajax.Updater(
> ''Pseudo'',
>
''check.php?pseudo=''+pseudoToTest+''&Date=''+escape(new
Date()),
> {
> method:''get'' ,
> onComplete:
> function succesRetourAjax (t)
> {
> if (t.responseText == "succes")
> {
> // Element.update("retourPseudo","available");
> $(imgPseudo).src = ''good.gif'';
> Element.hide("Pseudo");
> return true;
> }
> else
> {
> Element.show("retourPseudo");
> Element.update("Pseudo","Not available");
> $(imgPseudo).src = ''wrong.gif'';
> return false;
> }
> }
> }
> );
> }
> }
>
> function checkForm()
> {
> return disponibilitePseudo(''imgPseudo'');
> }
> </script>
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---