[jQuery] Re: consistently unable to get return false to work, why?

2009-07-28 Thread Eric Garside

Try starting off with a simplifying your selectors and the code in
general? .live(), in this case, isn't going to provide you much
benefit, as you're binding it to an element based on an ID, which
means there will only ever be a single element which this function
triggers for.

Try something like:

$(function(){
$('#getEmail').submit(function(){
var sid = $('.emailsButton', this).attr('id'),
email = $('#email');

email.after( isValidEmailAddress( email.val() ) ? 'works' :
'label class=errorEmail is not
valid!/label' );
return false;
});
});

On Jul 28, 12:30 pm, pedalpete p...@hearwhere.com wrote:
 That is what i've always thought James, but Firebug isn't showing any
 errors.

 I had actually edited the code and removed a context when i posted, so
 that is why that element didn't have a closing quote.

 But i had been constantly changing things, and no errors.

 However, you are correct that I had an error in the JS in that  I had
 gone back to using $ rather than jQuery in the script, and I think
 that is what was screwing this up.

 I still find it very strange that of the many, many times i've used
 'return false', i almost never get it to work the first time, and
 usually, i don't see what I've changed to make it work.

 Thanks for the help.
 Pete

 On Jul 27, 3:50 pm, James james.gp@gmail.com wrote:



  If the return false fails, it's usually something wrong with parsing
  your Javascript that causes the problem.
  For example:
  $(input#email).after(works);

  It's missing a closing quote () after email.

  On Jul 27, 12:28 pm, pedalpete p...@hearwhere.com wrote:

   Thanks John,

   I wasn't familiar with the .live() before, but of course I'll use that
   where I can.

   Though I'm honoured and humbled by your response, unfortunately, in
   this case, I'm using a 'submit', and the documentation says i can't
   use .live on submit currently. (I did try and, and it didn't work).

   .bind doesn't seem as efficient, as I'll be regularly binding/
   unbinding, but I've added that anyway, and still after the alerts, the
   form submits.
   As the form itself is created on the fly, i've put the bind inside the
   function which creates the form, and unbind before the form is first
   created so that i'm not stuck with the old data.

   Unfortunately,  i'm still stuck with the original problem, return
   false; appears to be ignored.

   On Jul 27, 2:14 pm, John Resig jere...@gmail.com wrote:

It looks like you're using the old liveQuery plugin. Why not just use
.bind() or .live()?

--John

On Mon, Jul 27, 2009 at 5:11 PM, pedalpete p...@hearwhere.com wrote:

 So, this isn't related to any one bit of code, but it seems to be a
 problem I run into almost everytime i need to stop a form or link for
 doing what it was originally intended to do (submit).

 Now, i have used return false; many times, but it never works at
 first.
 I'm never sure what I end up changing, but something changes, and then
 all of a sudden it works, and I am once again left stumped as to what
 I did.

 Yesterday, i renamed a class, and all of a sudden, it worked. Changed
 the class back, and guess what! It still works, though it hadn't
 before ...r

 Today, i'm trying to use a submit, check the e-mail address and then
 submit the form via ajax.
 Once again, i can't seem to stop the form from submitting.

 There are no other javascript errors coming up in firefox.
 my alerts work, so i'm in the right function, but then...the form
 submits.

 code
      jQuery('div#selected form#getEmail').livequery('submit', function
 (){
        var sid=jQuery('input.emailsButton', this).attr('id');
        var emailAddress=jQuery('input#email', this).val();
        alert(sid);
        if(isValidEmailAddress(emailAddress)) {
        alert('works');
                $(input#email).after(works);
        } else {
                alert('errored');
                $(input#email, this).after(label 
 class='error'Email is
 not
 valid!/label);

        }
        return false;
      });
 /code

 I've tried moving the return false; into the if/else, but no changes.

 As mentioned, i think the biggest problem isn't just with this code.
 There is something I seem to be doing consistently.

 Thanks


[jQuery] Re: consistently unable to get return false to work, why?

2009-07-28 Thread Michael Geary

The usual advice applies here: If you can post a link to a failing test page
with instructions to trigger the failure, I'll bet someone can take a look
at it and figure out what you're doing wrong.

-Mike



[jQuery] Re: consistently unable to get return false to work, why?

2009-07-27 Thread John Resig
It looks like you're using the old liveQuery plugin. Why not just use
.bind() or .live()?

--John


On Mon, Jul 27, 2009 at 5:11 PM, pedalpete p...@hearwhere.com wrote:


 So, this isn't related to any one bit of code, but it seems to be a
 problem I run into almost everytime i need to stop a form or link for
 doing what it was originally intended to do (submit).

 Now, i have used return false; many times, but it never works at
 first.
 I'm never sure what I end up changing, but something changes, and then
 all of a sudden it works, and I am once again left stumped as to what
 I did.

 Yesterday, i renamed a class, and all of a sudden, it worked. Changed
 the class back, and guess what! It still works, though it hadn't
 before ...r


 Today, i'm trying to use a submit, check the e-mail address and then
 submit the form via ajax.
 Once again, i can't seem to stop the form from submitting.

 There are no other javascript errors coming up in firefox.
 my alerts work, so i'm in the right function, but then...the form
 submits.

 code
  jQuery('div#selected form#getEmail').livequery('submit', function
 (){
var sid=jQuery('input.emailsButton', this).attr('id');
var emailAddress=jQuery('input#email', this).val();
alert(sid);
if(isValidEmailAddress(emailAddress)) {
alert('works');
$(input#email).after(works);
} else {
alert('errored');
$(input#email, this).after(label class='error'Email is
 not
 valid!/label);

}
return false;
  });
 /code

 I've tried moving the return false; into the if/else, but no changes.

 As mentioned, i think the biggest problem isn't just with this code.
 There is something I seem to be doing consistently.

 Thanks


[jQuery] Re: consistently unable to get return false to work, why?

2009-07-27 Thread pedalpete

Thanks John,

I wasn't familiar with the .live() before, but of course I'll use that
where I can.

Though I'm honoured and humbled by your response, unfortunately, in
this case, I'm using a 'submit', and the documentation says i can't
use .live on submit currently. (I did try and, and it didn't work).

.bind doesn't seem as efficient, as I'll be regularly binding/
unbinding, but I've added that anyway, and still after the alerts, the
form submits.
As the form itself is created on the fly, i've put the bind inside the
function which creates the form, and unbind before the form is first
created so that i'm not stuck with the old data.

Unfortunately,  i'm still stuck with the original problem, return
false; appears to be ignored.




On Jul 27, 2:14 pm, John Resig jere...@gmail.com wrote:
 It looks like you're using the old liveQuery plugin. Why not just use
 .bind() or .live()?

 --John



 On Mon, Jul 27, 2009 at 5:11 PM, pedalpete p...@hearwhere.com wrote:

  So, this isn't related to any one bit of code, but it seems to be a
  problem I run into almost everytime i need to stop a form or link for
  doing what it was originally intended to do (submit).

  Now, i have used return false; many times, but it never works at
  first.
  I'm never sure what I end up changing, but something changes, and then
  all of a sudden it works, and I am once again left stumped as to what
  I did.

  Yesterday, i renamed a class, and all of a sudden, it worked. Changed
  the class back, and guess what! It still works, though it hadn't
  before ...r

  Today, i'm trying to use a submit, check the e-mail address and then
  submit the form via ajax.
  Once again, i can't seem to stop the form from submitting.

  There are no other javascript errors coming up in firefox.
  my alerts work, so i'm in the right function, but then...the form
  submits.

  code
       jQuery('div#selected form#getEmail').livequery('submit', function
  (){
         var sid=jQuery('input.emailsButton', this).attr('id');
         var emailAddress=jQuery('input#email', this).val();
         alert(sid);
         if(isValidEmailAddress(emailAddress)) {
         alert('works');
                 $(input#email).after(works);
         } else {
                 alert('errored');
                 $(input#email, this).after(label class='error'Email is
  not
  valid!/label);

         }
         return false;
       });
  /code

  I've tried moving the return false; into the if/else, but no changes.

  As mentioned, i think the biggest problem isn't just with this code.
  There is something I seem to be doing consistently.

  Thanks


[jQuery] Re: consistently unable to get return false to work, why?

2009-07-27 Thread James

If the return false fails, it's usually something wrong with parsing
your Javascript that causes the problem.
For example:
$(input#email).after(works);

It's missing a closing quote () after email.

On Jul 27, 12:28 pm, pedalpete p...@hearwhere.com wrote:
 Thanks John,

 I wasn't familiar with the .live() before, but of course I'll use that
 where I can.

 Though I'm honoured and humbled by your response, unfortunately, in
 this case, I'm using a 'submit', and the documentation says i can't
 use .live on submit currently. (I did try and, and it didn't work).

 .bind doesn't seem as efficient, as I'll be regularly binding/
 unbinding, but I've added that anyway, and still after the alerts, the
 form submits.
 As the form itself is created on the fly, i've put the bind inside the
 function which creates the form, and unbind before the form is first
 created so that i'm not stuck with the old data.

 Unfortunately,  i'm still stuck with the original problem, return
 false; appears to be ignored.

 On Jul 27, 2:14 pm, John Resig jere...@gmail.com wrote:

  It looks like you're using the old liveQuery plugin. Why not just use
  .bind() or .live()?

  --John

  On Mon, Jul 27, 2009 at 5:11 PM, pedalpete p...@hearwhere.com wrote:

   So, this isn't related to any one bit of code, but it seems to be a
   problem I run into almost everytime i need to stop a form or link for
   doing what it was originally intended to do (submit).

   Now, i have used return false; many times, but it never works at
   first.
   I'm never sure what I end up changing, but something changes, and then
   all of a sudden it works, and I am once again left stumped as to what
   I did.

   Yesterday, i renamed a class, and all of a sudden, it worked. Changed
   the class back, and guess what! It still works, though it hadn't
   before ...r

   Today, i'm trying to use a submit, check the e-mail address and then
   submit the form via ajax.
   Once again, i can't seem to stop the form from submitting.

   There are no other javascript errors coming up in firefox.
   my alerts work, so i'm in the right function, but then...the form
   submits.

   code
        jQuery('div#selected form#getEmail').livequery('submit', function
   (){
          var sid=jQuery('input.emailsButton', this).attr('id');
          var emailAddress=jQuery('input#email', this).val();
          alert(sid);
          if(isValidEmailAddress(emailAddress)) {
          alert('works');
                  $(input#email).after(works);
          } else {
                  alert('errored');
                  $(input#email, this).after(label class='error'Email is
   not
   valid!/label);

          }
          return false;
        });
   /code

   I've tried moving the return false; into the if/else, but no changes.

   As mentioned, i think the biggest problem isn't just with this code.
   There is something I seem to be doing consistently.

   Thanks