[jQuery] Re: Disable a link temporarily

2009-02-09 Thread rob303

Thank you for the replies.  I like the toggle idea.  It's simple and
it works.

Cheers,

Rob.

On Feb 7, 11:35 am, donb falconwatc...@comcast.net wrote:
 Rather than bindin/unbinding events, why not put a hidden label (or
 tag of your choice) there with the same text, then toggle between
 them:

 $(a, label).toggle();

 Show the anchor or show the label.

 On Feb 7, 6:07 am, jQuery Lover ilovejqu...@gmail.com wrote:

   $('a.show_reset_pass_box').unbind('click');

  This line is unbinding ALL click events. So the second click binding
  function is not fired, since it's not bound...

  
  Read jQuery HowTo Resource  -  http://jquery-howto.blogspot.com

  On Sat, Feb 7, 2009 at 2:48 PM,rob303rob.cub...@googlemail.com wrote:

   Hi,

   This should be easy.

   I want to disable a link and then re-enable it later.  I have:

   $('a.show_reset_pass_box').click(function() {
      // do some stuff
      $('a.show_reset_pass_box').unbind('click');
      return false;
    });

   Which works just fine.  But then when I try to do:

   $('a.close_reset_pass_box').click(function() {
      // do some stuff
      $('a.show_reset_pass_box').bind('click');
      return false;
    });

   The click event isn't bound back onto the anchor.

   The anchor looks like this:

   a class=show_reset_pass_box title=Lost Password?Lost Password?/
   a

   What am I doing wrong?

   Many thanks in advance for any hekp.

   Rob.


[jQuery] Disable a link temporarily

2009-02-07 Thread rob303

Hi,

This should be easy.

I want to disable a link and then re-enable it later.  I have:

$('a.show_reset_pass_box').click(function() {
// do some stuff
$('a.show_reset_pass_box').unbind('click');
return false;
  });

Which works just fine.  But then when I try to do:

$('a.close_reset_pass_box').click(function() {
// do some stuff
$('a.show_reset_pass_box').bind('click');
return false;
  });

The click event isn't bound back onto the anchor.

The anchor looks like this:

a class=show_reset_pass_box title=Lost Password?Lost Password?/
a

What am I doing wrong?

Many thanks in advance for any hekp.

Rob.


[jQuery] Dynamic height and animation

2009-02-04 Thread rob303

Hi All,

I'm at a bit of a loss here.  I have a div which contains a swf.  The
swf has various panels that can be expanded and contracted vertically
so it's height can grow  It's embedded using the jQuery flash plug-in
and it has a height of 100%.  The div itself has a starting height of
285px..  The problem I face is that the designer wants to place an
html banner ad below this swf and when a user expands the height of
the swf the banner should slide down the page.

Now I can easily change the height of the div containing the flash
with something like:

$.fn.searchPanelHeight = function(h) {
  $('div.search_panel').height(h);
};

This function is called by the swf which sends it the height (h)
variable.  This works but the height change is instant which causes
the banner below to simply jump up and down the page.  How can I
animate this change in height so that the banner slides down as the
div expands?

Many thanks in advance for any help!

Rob.


[jQuery] Re: slideUp/Down jumpy in Firefox 3 but not in IE7?

2009-02-04 Thread rob303

I was struggling with this issue a few days ago.  See:

http://groups.google.com/group/jquery-en/browse_thread/thread/e24b99e5d6d14037/634d9d35155fc85a

On Feb 4, 5:37 pm, Andy Matthews li...@commadelimited.com wrote:
 The jQuery team freely admits that they optimize for IE more so than the
 other browsers. So it's distinctly possible that this is true.

 -Original Message-
 From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On

 Behalf Of Sam H
 Sent: Wednesday, February 04, 2009 11:28 AM
 To: jQuery (English)
 Subject: [jQuery] slideUp/Down jumpy in Firefox 3 but not in IE7?

 I don't remember if it was like this in jQuery 1.2, but I have 1.3.1 and I
 can clearly see that slideDown/Up is much smoother in IE7 than in Firefox 3.

 Is it just me?


[jQuery] Re: Getting the height of a hidden div in Firefox

2009-01-31 Thread rob303

Hi Tommy,

Many thanks.  That's exactly what I came up with over night.

$(this).next().css('display', 'block');
var h = $(this).next().height();
$(this).next().hide();
$(this).addClass('accordion_selected').next().height(h).slideDown
({duration: 700, easing: 'easeInOutQuad'});

Gives me the correct height in FF and it happens so fast that the div
isn't shown.  The slideDown is now perfectly smooth in both browsers.

Cheers,

Rob.

On Jan 31, 3:04 pm, omtay38 omta...@gmail.com wrote:
 I know its probably not the best solution, but what if you showed the
 div just long enough to get the height, hid it again and then slid it
 down. You could prevent the div from actually showing by giving it
 something like .css(left,-1px) before using .show(). Just a
 thought.

 Tommy

 On Jan 30, 2:00 pm, rob303 rob.cub...@googlemail.com wrote:

  Oh, one other thing.  If I call .css('display', 'block') on the
  element before using height() FF gives me the correct value of 240px.
  Obviously, that breaks the accordion because I want the element
  hidden!

  /me scratches head ...

  Rob.

  On Jan 30, 7:57 pm, rob303 rob.cub...@googlemail.com wrote:

   Thanks for the reply Eric.  But what have different box models got to
   do with it? I'm not setting any border or padding properties on my
   hidden div that would effect the height.  And the difference between
   the two browsers is huge.  IE says 240px and FF says 160px.  I
   certainly don't have 80px worth of padding on that element ...

   Rob.

   On Jan 30, 7:45 pm, Eric Garside gars...@gmail.com wrote:

Different box models. I'd read up more on the difference between the
IE/FF box models to point you in the right direction. I'd give you a
quick tutorial, but I get out at 3 on Fridays! :D

On Jan 30, 1:52 pm, rob303 rob.cub...@googlemail.com wrote:

 Hi,

 I've been working on this for days.  The chaps on IRC couldn't find an
 answer so I thought I'd post it here just in case anyone knows what's
 going on.

 I have a basic accordion type feature.  The designer wants to be able
 to open more than one of hidden the sections at once ...

 So, here is my code:

 $(.accordion .accordion_header).click(function() {
     if($(this).hasClass('accordion_selected')) {
           $(this).removeClass('accordion_selected').next().slideUp
 ({duration: 'slow', easing: 'easeInOutQuad'});
         } else {
           $(this).addClass('accordion_selected').next().slideDown
 ({duration: 'slow', easing: 'easeInOutQuad'});
         }
   }).next().hide();

 .accordion {
   width: 97%;
   list-style-type: none;

 }

 .accordion_header {
   display: block;
   height: 20px;
   background: url(../images/bgd_accordion_off.gif) repeat-x;
   padding: 5px 10px 0 10px;

 }

 .accordion_header:hover {
   background: url(../images/bgd_accordion_on.gif) repeat-x;
   color: #d7d7d9;

 }

 .accordion_selected {
   background: url(../images/bgd_accordion_on.gif) repeat-x;
   color: #d7d7d9;

 }

 .accordion_section {
   display: block;
   line-height: 20px;
   padding: 0 10px 0 10px;

 }

 ul class=accordion
   li
     a href=javascript:; class=accordion_headerheading/a
     div class=accordion_section
       A bunch of text
     /div
   /li
 /ul

 The problem I face is that the content within the hidden div
 (accordion_section) is db driven so I have no idea what content to put
 in there.  This means I cannot fix the height of those divs.  This in
 turn breaks the animate on the slideDown function.  If I set the
 height of the div the animate is perfect.  Without it everythings all
 jumpy and broken looking.  So I figured that all I needed to do was to
 get the height of the hidden div and then apply it using  a css()
 call.  This works fine in IE but Firefox doesn't seem able to give me
 the correct height for the div.  For example if I use this code:

 var h = $(this).next().height();
 alert(h);

 IE gives me 240 - which correct for that particular div.  But firefox
 gives 160 for the same div! Anyone know why?

 Many thanks in advance for any help.

 Rob.


[jQuery] Getting the height of a hidden div in Firefox

2009-01-30 Thread rob303

Hi,

I've been working on this for days.  The chaps on IRC couldn't find an
answer so I thought I'd post it here just in case anyone knows what's
going on.

I have a basic accordion type feature.  The designer wants to be able
to open more than one of hidden the sections at once ...

So, here is my code:

$(.accordion .accordion_header).click(function() {
if($(this).hasClass('accordion_selected')) {
  $(this).removeClass('accordion_selected').next().slideUp
({duration: 'slow', easing: 'easeInOutQuad'});
} else {
  $(this).addClass('accordion_selected').next().slideDown
({duration: 'slow', easing: 'easeInOutQuad'});
}
  }).next().hide();

.accordion {
  width: 97%;
  list-style-type: none;
}

.accordion_header {
  display: block;
  height: 20px;
  background: url(../images/bgd_accordion_off.gif) repeat-x;
  padding: 5px 10px 0 10px;
}

.accordion_header:hover {
  background: url(../images/bgd_accordion_on.gif) repeat-x;
  color: #d7d7d9;
}

.accordion_selected {
  background: url(../images/bgd_accordion_on.gif) repeat-x;
  color: #d7d7d9;
}

.accordion_section {
  display: block;
  line-height: 20px;
  padding: 0 10px 0 10px;
}

ul class=accordion
  li
a href=javascript:; class=accordion_headerheading/a
div class=accordion_section
  A bunch of text
/div
  /li
/ul

The problem I face is that the content within the hidden div
(accordion_section) is db driven so I have no idea what content to put
in there.  This means I cannot fix the height of those divs.  This in
turn breaks the animate on the slideDown function.  If I set the
height of the div the animate is perfect.  Without it everythings all
jumpy and broken looking.  So I figured that all I needed to do was to
get the height of the hidden div and then apply it using  a css()
call.  This works fine in IE but Firefox doesn't seem able to give me
the correct height for the div.  For example if I use this code:

var h = $(this).next().height();
alert(h);

IE gives me 240 - which correct for that particular div.  But firefox
gives 160 for the same div! Anyone know why?

Many thanks in advance for any help.

Rob.


[jQuery] Re: Getting the height of a hidden div in Firefox

2009-01-30 Thread rob303

Thanks for the reply Eric.  But what have different box models got to
do with it? I'm not setting any border or padding properties on my
hidden div that would effect the height.  And the difference between
the two browsers is huge.  IE says 240px and FF says 160px.  I
certainly don't have 80px worth of padding on that element ...

Rob.

On Jan 30, 7:45 pm, Eric Garside gars...@gmail.com wrote:
 Different box models. I'd read up more on the difference between the
 IE/FF box models to point you in the right direction. I'd give you a
 quick tutorial, but I get out at 3 on Fridays! :D

 On Jan 30, 1:52 pm, rob303 rob.cub...@googlemail.com wrote:

  Hi,

  I've been working on this for days.  The chaps on IRC couldn't find an
  answer so I thought I'd post it here just in case anyone knows what's
  going on.

  I have a basic accordion type feature.  The designer wants to be able
  to open more than one of hidden the sections at once ...

  So, here is my code:

  $(.accordion .accordion_header).click(function() {
      if($(this).hasClass('accordion_selected')) {
            $(this).removeClass('accordion_selected').next().slideUp
  ({duration: 'slow', easing: 'easeInOutQuad'});
          } else {
            $(this).addClass('accordion_selected').next().slideDown
  ({duration: 'slow', easing: 'easeInOutQuad'});
          }
    }).next().hide();

  .accordion {
    width: 97%;
    list-style-type: none;

  }

  .accordion_header {
    display: block;
    height: 20px;
    background: url(../images/bgd_accordion_off.gif) repeat-x;
    padding: 5px 10px 0 10px;

  }

  .accordion_header:hover {
    background: url(../images/bgd_accordion_on.gif) repeat-x;
    color: #d7d7d9;

  }

  .accordion_selected {
    background: url(../images/bgd_accordion_on.gif) repeat-x;
    color: #d7d7d9;

  }

  .accordion_section {
    display: block;
    line-height: 20px;
    padding: 0 10px 0 10px;

  }

  ul class=accordion
    li
      a href=javascript:; class=accordion_headerheading/a
      div class=accordion_section
        A bunch of text
      /div
    /li
  /ul

  The problem I face is that the content within the hidden div
  (accordion_section) is db driven so I have no idea what content to put
  in there.  This means I cannot fix the height of those divs.  This in
  turn breaks the animate on the slideDown function.  If I set the
  height of the div the animate is perfect.  Without it everythings all
  jumpy and broken looking.  So I figured that all I needed to do was to
  get the height of the hidden div and then apply it using  a css()
  call.  This works fine in IE but Firefox doesn't seem able to give me
  the correct height for the div.  For example if I use this code:

  var h = $(this).next().height();
  alert(h);

  IE gives me 240 - which correct for that particular div.  But firefox
  gives 160 for the same div! Anyone know why?

  Many thanks in advance for any help.

  Rob.


[jQuery] Re: Getting the height of a hidden div in Firefox

2009-01-30 Thread rob303

Oh, one other thing.  If I call .css('display', 'block') on the
element before using height() FF gives me the correct value of 240px.
Obviously, that breaks the accordion because I want the element
hidden!

/me scratches head ...

Rob.

On Jan 30, 7:57 pm, rob303 rob.cub...@googlemail.com wrote:
 Thanks for the reply Eric.  But what have different box models got to
 do with it? I'm not setting any border or padding properties on my
 hidden div that would effect the height.  And the difference between
 the two browsers is huge.  IE says 240px and FF says 160px.  I
 certainly don't have 80px worth of padding on that element ...

 Rob.

 On Jan 30, 7:45 pm, Eric Garside gars...@gmail.com wrote:

  Different box models. I'd read up more on the difference between the
  IE/FF box models to point you in the right direction. I'd give you a
  quick tutorial, but I get out at 3 on Fridays! :D

  On Jan 30, 1:52 pm, rob303 rob.cub...@googlemail.com wrote:

   Hi,

   I've been working on this for days.  The chaps on IRC couldn't find an
   answer so I thought I'd post it here just in case anyone knows what's
   going on.

   I have a basic accordion type feature.  The designer wants to be able
   to open more than one of hidden the sections at once ...

   So, here is my code:

   $(.accordion .accordion_header).click(function() {
       if($(this).hasClass('accordion_selected')) {
             $(this).removeClass('accordion_selected').next().slideUp
   ({duration: 'slow', easing: 'easeInOutQuad'});
           } else {
             $(this).addClass('accordion_selected').next().slideDown
   ({duration: 'slow', easing: 'easeInOutQuad'});
           }
     }).next().hide();

   .accordion {
     width: 97%;
     list-style-type: none;

   }

   .accordion_header {
     display: block;
     height: 20px;
     background: url(../images/bgd_accordion_off.gif) repeat-x;
     padding: 5px 10px 0 10px;

   }

   .accordion_header:hover {
     background: url(../images/bgd_accordion_on.gif) repeat-x;
     color: #d7d7d9;

   }

   .accordion_selected {
     background: url(../images/bgd_accordion_on.gif) repeat-x;
     color: #d7d7d9;

   }

   .accordion_section {
     display: block;
     line-height: 20px;
     padding: 0 10px 0 10px;

   }

   ul class=accordion
     li
       a href=javascript:; class=accordion_headerheading/a
       div class=accordion_section
         A bunch of text
       /div
     /li
   /ul

   The problem I face is that the content within the hidden div
   (accordion_section) is db driven so I have no idea what content to put
   in there.  This means I cannot fix the height of those divs.  This in
   turn breaks the animate on the slideDown function.  If I set the
   height of the div the animate is perfect.  Without it everythings all
   jumpy and broken looking.  So I figured that all I needed to do was to
   get the height of the hidden div and then apply it using  a css()
   call.  This works fine in IE but Firefox doesn't seem able to give me
   the correct height for the div.  For example if I use this code:

   var h = $(this).next().height();
   alert(h);

   IE gives me 240 - which correct for that particular div.  But firefox
   gives 160 for the same div! Anyone know why?

   Many thanks in advance for any help.

   Rob.


[jQuery] Re: Identify last keeypess

2009-01-21 Thread rob303

Many thanks James.

On Jan 21, 8:58 am, James Hughes j.hug...@kainos.com wrote:
 Stick autocomplete=off in your input tag and that should do it

 input type=text name=login autocomplete=off /
 Though this might cause XHTML validation to fail if that's an issue

 

 From: jquery-en@googlegroups.com on behalf of rob303
 Sent: Tue 20/01/2009 16:40
 To: jQuery (English)
 Subject: [jQuery] Re: Identify last keeypess

 Thanks again.  On reflection I think you are right James.  I should
 probably disable autocomplete for this field and doing so would
 resolve my issue.

 However, I've taken a quick look at the nocomplete plugin and that's
 not really what I want as it breaks some other functionality I have on
 those inputs.

 Is there a simple an elegant way to do it?

 Thanks!

 Rob.

 On Jan 20, 3:24 pm, James Hughes j.hug...@kainos.com wrote:

  On a side note...

  Do you want/need autocomplete becasue it is possible to stop a textfield 
  being capable of autocomplete.  I ask simply becasue your example uses a 
  login field and sometimes it's not security concious to allow autocomplete 
  on some login fields.

  Otherwise you'll just have to log what key was pressed in an external 
  variable EVERYTIME a key is pressed and check that variale at the start of 
  every keypress event.

  James

 
 This e-mail is intended solely for the addressee and is strictly 
 confidential; if you are not the addressee please destroy the message and all 
 copies. Any opinion or information contained in this email or its attachments 
 that does not relate to the business of Kainos
 is personal to the sender and is not given by or endorsed by Kainos. Kainos 
 is the trading name of Kainos Software Limited, registered in Northern 
 Ireland under company number: NI19370, having its registered offices at: 
 Kainos House, 4-6 Upper Crescent, Belfast, BT7 1NT,
 Northern Ireland. Registered in the UK for VAT under number: 454598802 and 
 registered in Ireland for VAT under number: 9950340E. This email has been 
 scanned for all known viruses by MessageLabs but is not guaranteed to be 
 virus free; further terms and conditions may be
 found on our website -www.kainos.com


[jQuery] Identify last keeypess

2009-01-20 Thread rob303

Hi,

I've been searching the web for an answer to this but haven't been
able to find one.

I have a form which is using an image as it's submit button and I want
users to be able to submit the form by pressing enter.  Simple enough:

// submit the login form if the user hits enter
$('.login_input').keypress(function(event) {
  if(event.keyCode == 13) {
$('#login').submit();
  }
});

That works fine.  However, if the user is presented with a list of
options for the text input by their browser and they use the up and
down arrows keys to highlight, then enter to select an option the form
gets submitted.  Not ideal!  So, my question is how can I identify the
last key press before the user hits enter?  Ideally my logic will be
something like:

$('.login_input').keypress(function(event) {
  if(LAST KEYPRESS IS NOT UP OR DOWN ARROW) {
if(event.keyCode == 13) {
  $('#login').submit();
}
  }
});

Hopefully, that makes sense!  Many thanks in advance for any help.

Rob.


[jQuery] Re: Identify last keeypess

2009-01-20 Thread rob303

Hi James,

Thanks for the reply.  It's just a standard text input:

input class=login_input type=text name=user value= /

When the user clicks and starts to type the browser may, depending on
what's been entered before, give a list of options.  Some users might
use the down or up arrow keys to highlight one of the options and then
hit submit to select it.  This, I think, is standard browser behaviour
- unless I have it wrong?  Unfortunately for me, hitting enter at that
point will submit the form.

Any help would be much appreciated!

Rob.

On Jan 20, 1:56 pm, James Hughes j.hug...@kainos.com wrote:
 Rob,

 Is this some sort of autocomplete text box or is it a select input?

 James

 

 From: jquery-en@googlegroups.com on behalf of rob303
 Sent: Tue 20/01/2009 13:44
 To: jQuery (English)
 Subject: [jQuery] Identify last keeypess

 Hi,

 I've been searching the web for an answer to this but haven't been
 able to find one.

 I have a form which is using an image as it's submit button and I want
 users to be able to submit the form by pressing enter.  Simple enough:

 // submit the login form if the user hits enter
 $('.login_input').keypress(function(event) {
   if(event.keyCode == 13) {
     $('#login').submit();
   }

 });

 That works fine.  However, if the user is presented with a list of
 options for the text input by their browser and they use the up and
 down arrows keys to highlight, then enter to select an option the form
 gets submitted.  Not ideal!  So, my question is how can I identify the
 last key press before the user hits enter?  Ideally my logic will be
 something like:

 $('.login_input').keypress(function(event) {
   if(LAST KEYPRESS IS NOT UP OR DOWN ARROW) {
     if(event.keyCode == 13) {
       $('#login').submit();
     }
   }

 });

 Hopefully, that makes sense!  Many thanks in advance for any help.

 Rob.

 
 This e-mail is intended solely for the addressee and is strictly 
 confidential; if you are not the addressee please destroy the message and all 
 copies. Any opinion or information contained in this email or its attachments 
 that does not relate to the business of Kainos
 is personal to the sender and is not given by or endorsed by Kainos. Kainos 
 is the trading name of Kainos Software Limited, registered in Northern 
 Ireland under company number: NI19370, having its registered offices at: 
 Kainos House, 4-6 Upper Crescent, Belfast, BT7 1NT,
 Northern Ireland. Registered in the UK for VAT under number: 454598802 and 
 registered in Ireland for VAT under number: 9950340E. This email has been 
 scanned for all known viruses by MessageLabs but is not guaranteed to be 
 virus free; further terms and conditions may be
 found on our website -www.kainos.com


[jQuery] Re: Identify last keeypess

2009-01-20 Thread rob303

Thanks again.  On reflection I think you are right James.  I should
probably disable autocomplete for this field and doing so would
resolve my issue.

However, I've taken a quick look at the nocomplete plugin and that's
not really what I want as it breaks some other functionality I have on
those inputs.

Is there a simple an elegant way to do it?

Thanks!

Rob.

On Jan 20, 3:24 pm, James Hughes j.hug...@kainos.com wrote:
 On a side note...

 Do you want/need autocomplete becasue it is possible to stop a textfield 
 being capable of autocomplete.  I ask simply becasue your example uses a 
 login field and sometimes it's not security concious to allow autocomplete on 
 some login fields.

 Otherwise you'll just have to log what key was pressed in an external 
 variable EVERYTIME a key is pressed and check that variale at the start of 
 every keypress event.

 James


[jQuery] Hide / show password field with focus

2009-01-06 Thread rob303

Hi,

I've put together a couple of small functions to handle the removal /
restore of the default text inside some text inputs.  One of these
inputs is a password field.  I'm showing the user a standard text
field containing the text 'Password'.  When the user clicks in the box
the standard text field is hidden and a proper password box is show.
The following works fine:

$('.login_input').click(function() {
if(this.value == this.defaultValue) {
  this.value = '';
}
if(this.name == 'fake_pass') {
  $('.header_login_right_fake').hide();
  $('.header_login_right_real').show();
}
  });

  $('.login_input').blur(function() {
if(this.value == '') {
  this.value = this.defaultValue;
  if(this.name == 'pass') {
$('.header_login_right_real').hide();
$('.header_login_right_fake').show();
$('html').focus();
  }
}
  });

However, the newly displayed password box is not in focus and the user
has to click again to start typing their password.  So, in an attempt
to correct this problem I added '$('.login_input').focus();'. This
works and focus is added to the password input but it now breaks the
recall of the default text.  Now when a user clicks away from the box
and calls the onblur() function the default text is not displayed.
Here is all my code plus the HMTL:

--
$('.login_input').click(function() {
if(this.value == this.defaultValue) {
  this.value = '';
}
if(this.name == 'fake_pass') {
  $('.header_login_right_fake').hide();
  $('.header_login_right_real').show();
  $('.login_input').focus();
}
  });

  $('.login_input').blur(function() {
if(this.value == '') {
  this.value = this.defaultValue;
  if(this.name == 'pass') {
$('.header_login_right_real').hide();
$('.header_login_right_fake').show();
$('html').focus();
  }
}
  });
--
div class=header_login_left
  input class=login_input type=text name=email value=?php
echo TEXT_USER_NAME; ? /
/div
div class=header_login_right_fake
  input class=login_input type=text name=fake_pass value=?php
echo TEXT_PASSWORD; ? /
/div
div class=header_login_right_real
  input class=login_input type=password name=pass value= /
 /div
--

Can anybody see where I'm going wrong or how I could improve these
functions generally?  I'm very new to jQuery so please feel free to
talk down to me!  Thanks in advance for any help.

Rob.


[jQuery] Re: Hide / show password field with focus

2009-01-06 Thread rob303

Hi,

I'm still really struggling with this.  Any help would be greatly
appreciated!

Rob.

On Jan 6, 11:40 am, rob303 r...@cube33.com wrote:
 Hi,

 I've put together a couple of small functions to handle the removal /
 restore of the default text inside some text inputs.  One of these
 inputs is a password field.  I'm showing the user a standard text
 field containing the text 'Password'.  When the user clicks in the box
 the standard text field is hidden and a proper password box is show.
 The following works fine:

 $('.login_input').click(function() {
     if(this.value == this.defaultValue) {
       this.value = '';
     }
     if(this.name == 'fake_pass') {
       $('.header_login_right_fake').hide();
       $('.header_login_right_real').show();
     }
   });

   $('.login_input').blur(function() {
     if(this.value == '') {
       this.value = this.defaultValue;
       if(this.name == 'pass') {
         $('.header_login_right_real').hide();
         $('.header_login_right_fake').show();
         $('html').focus();
       }
     }
   });

 However, the newly displayed password box is not in focus and the user
 has to click again to start typing their password.  So, in an attempt
 to correct this problem I added '$('.login_input').focus();'. This
 works and focus is added to the password input but it now breaks the
 recall of the default text.  Now when a user clicks away from the box
 and calls the onblur() function the default text is not displayed.
 Here is all my code plus the HMTL:

 --
 $('.login_input').click(function() {
     if(this.value == this.defaultValue) {
       this.value = '';
     }
     if(this.name == 'fake_pass') {
       $('.header_login_right_fake').hide();
       $('.header_login_right_real').show();
       $('.login_input').focus();
     }
   });

   $('.login_input').blur(function() {
     if(this.value == '') {
       this.value = this.defaultValue;
       if(this.name == 'pass') {
         $('.header_login_right_real').hide();
         $('.header_login_right_fake').show();
         $('html').focus();
       }
     }
   });
 --
 div class=header_login_left
   input class=login_input type=text name=email value=?php
 echo TEXT_USER_NAME; ? /
 /div
 div class=header_login_right_fake
   input class=login_input type=text name=fake_pass value=?php
 echo TEXT_PASSWORD; ? /
 /div
 div class=header_login_right_real
   input class=login_input type=password name=pass value= /
  /div
 --

 Can anybody see where I'm going wrong or how I could improve these
 functions generally?  I'm very new to jQuery so please feel free to
 talk down to me!  Thanks in advance for any help.

 Rob.


[jQuery] Re: Hide / show password field with focus

2009-01-06 Thread rob303

Thank you Daniel.  That's perfect.  This was hole in my understanding:

$('.header_login_right_fake  .login_input')[0].value = $
('.header_login_right_fake  .login_input')[0].defaultValue;

How to access the attributes of the inputs!  My function now looks
like this:

// restore default text in login inputs
$('.login_input').blur(function() {
  if(this.value == '') {
this.value = this.defaultValue;
if(this.name == 'pass') {
  $('.header_login_right_fake  .login_input')[0].value = $
('.header_login_right_fake  .login_input')[0].defaultValue;
  $('.header_login_right_real').hide();
  $('.header_login_right_fake').show();
}
  }
});

It seems to work perfectly (although I haven't tested it in Safari
yet).  Many thanks for all your help :)

Rob.





On Jan 6, 7:37 pm, Daniel dqmin...@gmail.com wrote:
 When you click outside the password field, the field is still
 input class=login_input type=password name=pass value= /
 not
 input class=login_input type=text name=fake_pass value=?php
 echo TEXT_PASSWORD; ? /

 Therefore, default value is '' , not ?php
 echo TEXT_PASSWORD; ?

 a quick fix to your code ( not tested )
 $('.login_input').blur(function(){
                 if(this.value === ''  this.name === 'pass'){
                         $('.header_login_right_fake  .login_input')[0].value 
 = $
 ('.header_login_right_fake  .login_input')[0].defaultValue
                 } else{
                     if (this.value === ''){
                                 this.value = this.defaultValue
                         }
                 }
                 if(this.name === 'pass'){
                         $('.header_login_right_real').hide();
                         $('.header_login_right_fake').show();
                         $('html').focus();
                 }

 });

 On Jan 6, 11:51 pm, rob303 r...@cube33.com wrote:

  Hi,

  I'm still really struggling with this.  Any help would be greatly
  appreciated!

  Rob.

  On Jan 6, 11:40 am, rob303 r...@cube33.com wrote:

   Hi,

   I've put together a couple of small functions to handle the removal /
   restore of the default text inside some text inputs.  One of these
   inputs is a password field.  I'm showing the user a standard text
   field containing the text 'Password'.  When the user clicks in the box
   the standard text field is hidden and a proper password box is show.
   The following works fine:

   $('.login_input').click(function() {
       if(this.value == this.defaultValue) {
         this.value = '';
       }
       if(this.name == 'fake_pass') {
         $('.header_login_right_fake').hide();
         $('.header_login_right_real').show();
       }
     });

     $('.login_input').blur(function() {
       if(this.value == '') {
         this.value = this.defaultValue;
         if(this.name == 'pass') {
           $('.header_login_right_real').hide();
           $('.header_login_right_fake').show();
           $('html').focus();
         }
       }
     });

   However, the newly displayed password box is not in focus and the user
   has to click again to start typing their password.  So, in an attempt
   to correct this problem I added '$('.login_input').focus();'. This
   works and focus is added to the password input but it now breaks the
   recall of the default text.  Now when a user clicks away from the box
   and calls the onblur() function the default text is not displayed.
   Here is all my code plus the HMTL:

   --
   $('.login_input').click(function() {
       if(this.value == this.defaultValue) {
         this.value = '';
       }
       if(this.name == 'fake_pass') {
         $('.header_login_right_fake').hide();
         $('.header_login_right_real').show();
         $('.login_input').focus();
       }
     });

     $('.login_input').blur(function() {
       if(this.value == '') {
         this.value = this.defaultValue;
         if(this.name == 'pass') {
           $('.header_login_right_real').hide();
           $('.header_login_right_fake').show();
           $('html').focus();
         }
       }
     });
   --
   div class=header_login_left
     input class=login_input type=text name=email value=?php
   echo TEXT_USER_NAME; ? /
   /div
   div class=header_login_right_fake
     input class=login_input type=text name=fake_pass value=?php
   echo TEXT_PASSWORD; ? /
   /div
   div class=header_login_right_real
     input class=login_input type=password name=pass value= /
    /div
   --

   Can anybody see where I'm going wrong or how I could improve these
   functions generally?  I'm very new to jQuery so please feel free to
   talk down to me!  Thanks in advance for any help.

   Rob.


[jQuery] Re: How to handle responses from PHP with $.ajax()

2009-01-04 Thread rob303

Hi,

Many thanks for the help.  I had a go at implementing what you
suggested but I'm clearly still missing something.

Here is my $.ajax() call:
--
$(document).ready(function(){
$(form#submit).submit(function() {
  var email = $('#email').attr('value');
  $.ajax({
type: POST,
url: ajax.php,
data: email=+ email,
success: function(del){
  if(del.result == 1) {
$('form#submit').hide();
$('div.success').fadeIn('medium');
  } else {
$('div.error').show();
  }
}
  });
  return false;
});
  });
--

And here is my json array in PHP:
--
$message = $_POST['email'];

if($message != '') {
  mail('some-em...@email.com', 'Ajax test', $message);
  $json_data = array('result' = 1).
} else {
  $json_data = array('result' = 0, 'error' = 'This is an error').
}

json_encode($json_data);
--

I'm obviously not accessing del.result correctly because $
('div.error').show(); is always executed regardless of the value of
result.  Where am I going wrong?

Thanks in advance,

Rob.

On Jan 4, 2:41 pm, donb falconwatc...@comcast.net wrote:
 Return a JSON object.

 Construct a PHP array such as $json_data = array('result' = 0,
 'error' = 'This is an error').  End your PHP script with json_encode
 ($json_data).  Then you can reference del.result and del.error (I'm
 referring to your definition of the' success' function from your
 sample code)

 On Jan 4, 7:16 am, rob303 r...@cube33.com wrote:

  Hi,

  I'm new to ajax and jquery but I'm not new to PHP.  The following
  example seems to work okay to a point but I can't figure out how to
  handle data validation errors generated in my PHP.

  In my example I want to post some data to a script called ajax.php.
  That script will check the data for validity and then return true or
  false depending on the outcome of the checks. It will also set an
  appropriate error message.

  How can I handle the returned data and display an error message if
  needed in ajax?

  --
  HTML / Ajax - test.php
  --
  ?php

  require_once(includes.php);

  ?
  html
    head
      script src=js/jquery.js type=text/javascript/script
      script type=text/javascript
        $(document).ready(function(){
          $(form#submit).submit(function() {
            var email = $('#email').attr('value');
            $.ajax({
              type: POST,
              url: ajax.php,
              data: email=+ email,
              success: function(del){
                $('form#submit').hide();
                $('div.success').fadeIn('medium');
                // what if the data failed validation in PHP?
                // we need to show 'div.error.
              }
            });
            return false;
          });
        });
      /script
    /head
    body
      form id=submit method=post
        Email:
        input id=email class=text name=email size=20
  type=text /
        input type=submit value=send mail /
      /form
      div class=success style=display:none;
        Email sent.
      /div
      div class=error
        ?php echo $userError; ?
      /div
    /body
  /html

  --
  PHP - ajax.php
  --
  ?php

  require_once(includes.php);

  $message = $_POST['email'];

  if($message != '') {
    mail('some-em...@email.com', 'Ajax test', $message);
    return 1;} else {

    $userError = Please enter your email address;
    return 0;

  }

  ?

  I've been searching the web for an answer but can't find one
  anywhere!  Any help would be greatly appreciated.


[jQuery] Re: How to handle responses from PHP with $.ajax()

2009-01-04 Thread rob303

Yes, the missing semicolons are an error in the post. I tried to echo
the json_encode() call but I still can't get it to work. If I leave
the email input blank no email is sent. If I enter a string the email
is sent. The 'div.error' is always displayed regardless what's posted.

Here's my full code again:

--
HTML / Ajax
--
?php

require_once(../inc/site_config.php);

require_once(SITE . /includes.php);
?
html
  head
script src=js/jquery.js type=text/javascript/script
script type=text/javascript
  $(document).ready(function(){
$(form#submit).submit(function() {
  var email = $('#email').attr('value');
  $.ajax({
type: POST,
url: ajax.php?v=1,
data: email=+ email,
success: function(res){
  if(res.result == 1) {
$('form#submit').hide();
$('div.success').fadeIn('medium');
  } else {
$('div.error').show();
  }
}
  });
  return false;
});
  });
/script
  /head
  body
  form id=submit method=post
Email:
input id=email class=text name=email size=20
type=text /
input type=submit value=send mail /
  /form
  div class=success style=display:none;
Email sent.
  /div
  div class=error style=display:none;err/div
  /body
/html

--
PHP
--
?php

require_once(includes.php);

$message = $_POST['email'];

if($message != '') {
  mail('some-em...@email.com', 'Ajax test', $message);
  $json_data = array('result' = 1);
} else {
  $json_data = array('result' = 0);
}

echo json_encode($json_data);

?
$message = $_POST['email'];

if($message != '') {
  mail('r...@cube33.com', 'Ajax test', $message);
  $json_data = array('result' = 1);
} else {
  $json_data = array('result' = 0);
}

echo json_encode($json_data);

?
--
On Jan 4, 5:44 pm, donb falconwatc...@comcast.net wrote:
 You must 'echo' the JSON output.  Also you indicate periods ending
 code lines, instead of semicolons but perhaps that's just an error in
 your post, not the actual code?

 On Jan 4, 10:38 am, rob303 r...@cube33.com wrote:

  Hi,

  Many thanks for the help.  I had a go at implementing what you
  suggested but I'm clearly still missing something.

  Here is my $.ajax() call:
  --
  $(document).ready(function(){
          $(form#submit).submit(function() {
            var email = $('#email').attr('value');
            $.ajax({
              type: POST,
              url: ajax.php,
              data: email=+ email,
              success: function(del){
                if(del.result == 1) {
                  $('form#submit').hide();
                  $('div.success').fadeIn('medium');
                } else {
                  $('div.error').show();
                }
              }
            });
            return false;
          });
        });
  --

  And here is my json array in PHP:
  --
  $message = $_POST['email'];

  if($message != '') {
    mail('some-em...@email.com', 'Ajax test', $message);
    $json_data = array('result' = 1).} else {

    $json_data = array('result' = 0, 'error' = 'This is an error').

  }

  json_encode($json_data);
  --

  I'm obviously not accessing del.result correctly because $
  ('div.error').show(); is always executed regardless of the value of
  result.  Where am I going wrong?

  Thanks in advance,

  Rob.

  On Jan 4, 2:41 pm, donb falconwatc...@comcast.net wrote:

   Return a JSON object.

   Construct a PHP array such as $json_data = array('result' = 0,
   'error' = 'This is an error').  End your PHP script with json_encode
   ($json_data).  Then you can reference del.result and del.error (I'm
   referring to your definition of the' success' function from your
   sample code)

   On Jan 4, 7:16 am, rob303 r...@cube33.com wrote:

Hi,

I'm new to ajax and jquery but I'm not new to PHP.  The following
example seems to work okay to a point but I can't figure out how to
handle data validation errors generated in my PHP.

In my example I want to post some data to a script called ajax.php.
That script will check the data for validity and then return true or
false depending on the outcome of the checks. It will also set an
appropriate error message.

How can I handle the returned data and display an error message if
needed in ajax?

--
HTML / Ajax - test.php
--
?php

require_once(includes.php);

?
html
  head
    script src=js/jquery.js type=text/javascript/script
    script type=text/javascript
      $(document).ready(function(){
        $(form#submit).submit(function() {
          var email = $('#email').attr('value');
          $.ajax({
            type: POST,
            url

[jQuery] Re: How to handle responses from PHP with $.ajax()

2009-01-04 Thread rob303

Interestingly, in the Firebug console I'm seeing the correct
responses:

{result:1}

or

{result:0}

How can I access these inside my $.ajax() call?

Many thanks again for all the help!

Rob.

On Jan 4, 5:57 pm, rob303 r...@cube33.com wrote:
 Yes, the missing semicolons are an error in the post. I tried to echo
 the json_encode() call but I still can't get it to work. If I leave
 the email input blank no email is sent. If I enter a string the email
 is sent. The 'div.error' is always displayed regardless what's posted.

 Here's my full code again:

 --
 HTML / Ajax
 --
 ?php

 require_once(../inc/site_config.php);

 require_once(SITE . /includes.php);
 ?
 html
   head
         script src=js/jquery.js type=text/javascript/script
     script type=text/javascript
       $(document).ready(function(){
         $(form#submit).submit(function() {
           var email = $('#email').attr('value');
           $.ajax({
             type: POST,
             url: ajax.php?v=1,
             data: email=+ email,
             success: function(res){
               if(res.result == 1) {
                 $('form#submit').hide();
                 $('div.success').fadeIn('medium');
               } else {
                 $('div.error').show();
               }
             }
           });
           return false;
         });
       });
     /script
   /head
   body
       form id=submit method=post
         Email:
         input id=email class=text name=email size=20
 type=text /
             input type=submit value=send mail /
           /form
       div class=success style=display:none;
         Email sent.
       /div
       div class=error style=display:none;err/div
   /body
 /html

 --
 PHP
 --
 ?php

 require_once(includes.php);

 $message = $_POST['email'];

 if($message != '') {
   mail('some-em...@email.com', 'Ajax test', $message);
   $json_data = array('result' = 1);} else {

   $json_data = array('result' = 0);

 }

 echo json_encode($json_data);

 ?
 $message = $_POST['email'];

 if($message != '') {
   mail('@cube33.com', 'Ajax test', $message);
   $json_data = array('result' = 1);} else {

   $json_data = array('result' = 0);

 }

 echo json_encode($json_data);

 ?
 --
 On Jan 4, 5:44 pm, donb falconwatc...@comcast.net wrote:

  You must 'echo' the JSON output.  Also you indicate periods ending
  code lines, instead of semicolons but perhaps that's just an error in
  your post, not the actual code?

  On Jan 4, 10:38 am, rob303 r...@cube33.com wrote:

   Hi,

   Many thanks for the help.  I had a go at implementing what you
   suggested but I'm clearly still missing something.

   Here is my $.ajax() call:
   --
   $(document).ready(function(){
           $(form#submit).submit(function() {
             var email = $('#email').attr('value');
             $.ajax({
               type: POST,
               url: ajax.php,
               data: email=+ email,
               success: function(del){
                 if(del.result == 1) {
                   $('form#submit').hide();
                   $('div.success').fadeIn('medium');
                 } else {
                   $('div.error').show();
                 }
               }
             });
             return false;
           });
         });
   --

   And here is my json array in PHP:
   --
   $message = $_POST['email'];

   if($message != '') {
     mail('some-em...@email.com', 'Ajax test', $message);
     $json_data = array('result' = 1).} else {

     $json_data = array('result' = 0, 'error' = 'This is an error').

   }

   json_encode($json_data);
   --

   I'm obviously not accessing del.result correctly because $
   ('div.error').show(); is always executed regardless of the value of
   result.  Where am I going wrong?

   Thanks in advance,

   Rob.

   On Jan 4, 2:41 pm, donb falconwatc...@comcast.net wrote:

Return a JSON object.

Construct a PHP array such as $json_data = array('result' = 0,
'error' = 'This is an error').  End your PHP script with json_encode
($json_data).  Then you can reference del.result and del.error (I'm
referring to your definition of the' success' function from your
sample code)

On Jan 4, 7:16 am, rob303 r...@cube33.com wrote:

 Hi,

 I'm new to ajax and jquery but I'm not new to PHP.  The following
 example seems to work okay to a point but I can't figure out how to
 handle data validation errors generated in my PHP.

 In my example I want to post some data to a script called ajax.php.
 That script will check the data for validity and then return true or
 false depending on the outcome of the checks. It will also set an
 appropriate error message.

 How can I handle the returned data and display an error message if
 needed in ajax?

 --
 HTML / Ajax - test.php

[jQuery] Re: How to handle responses from PHP with $.ajax()

2009-01-04 Thread rob303

Hi again,

I tried that but got the same results.

if(res.result == '1') {
  $('form#submit').hide();
  $('div.success').fadeIn('medium');
} else {
  $('div.error').show();
}

if(res.result == 1) {
  $('form#submit').hide();
  $('div.success').fadeIn('medium');
} else {
  $('div.error').show();
}

res.result is always false even though firebug says the response is
{result:1}.

Rob.



On Jan 4, 7:01 pm, donb falconwatc...@comcast.net wrote:
 On another thread, someone pointed out to me that json_encode was
 supposed to 'know' if the data values were numeric or string and only
 quote the latter.  That was not my experience, and perhaps not yours,
 either.  Try '1' as the value you compare to instead of 1.

 On Jan 4, 1:05 pm, rob303 r...@cube33.com wrote:

  Interestingly, in the Firebug console I'm seeing the correct
  responses:

  {result:1}

  or

  {result:0}

  How can I access these inside my $.ajax() call?

  Many thanks again for all the help!

  Rob.

  On Jan 4, 5:57 pm, rob303 r...@cube33.com wrote:

   Yes, the missing semicolons are an error in the post. I tried to echo
   the json_encode() call but I still can't get it to work. If I leave
   the email input blank no email is sent. If I enter a string the email
   is sent. The 'div.error' is always displayed regardless what's posted.

   Here's my full code again:

   --
   HTML / Ajax
   --
   ?php

   require_once(../inc/site_config.php);

   require_once(SITE . /includes.php);
   ?
   html
     head
           script src=js/jquery.js type=text/javascript/script
       script type=text/javascript
         $(document).ready(function(){
           $(form#submit).submit(function() {
             var email = $('#email').attr('value');
             $.ajax({
               type: POST,
               url: ajax.php?v=1,
               data: email=+ email,
               success: function(res){
                 if(res.result == 1) {
                   $('form#submit').hide();
                   $('div.success').fadeIn('medium');
                 } else {
                   $('div.error').show();
                 }
               }
             });
             return false;
           });
         });
       /script
     /head
     body
         form id=submit method=post
           Email:
           input id=email class=text name=email size=20
   type=text /
               input type=submit value=send mail /
             /form
         div class=success style=display:none;
           Email sent.
         /div
         div class=error style=display:none;err/div
     /body
   /html

   --
   PHP
   --
   ?php

   require_once(includes.php);

   $message = $_POST['email'];

   if($message != '') {
     mail('some-em...@email.com', 'Ajax test', $message);
     $json_data = array('result' = 1);} else {

     $json_data = array('result' = 0);

   }

   echo json_encode($json_data);

   ?
   $message = $_POST['email'];

   if($message != '') {
     mail('@cube33.com', 'Ajax test', $message);
     $json_data = array('result' = 1);} else {

     $json_data = array('result' = 0);

   }

   echo json_encode($json_data);

   ?
   --
   On Jan 4, 5:44 pm, donb falconwatc...@comcast.net wrote:

You must 'echo' the JSON output.  Also you indicate periods ending
code lines, instead of semicolons but perhaps that's just an error in
your post, not the actual code?

On Jan 4, 10:38 am, rob303 r...@cube33.com wrote:

 Hi,

 Many thanks for the help.  I had a go at implementing what you
 suggested but I'm clearly still missing something.

 Here is my $.ajax() call:
 --
 $(document).ready(function(){
         $(form#submit).submit(function() {
           var email = $('#email').attr('value');
           $.ajax({
             type: POST,
             url: ajax.php,
             data: email=+ email,
             success: function(del){
               if(del.result == 1) {
                 $('form#submit').hide();
                 $('div.success').fadeIn('medium');
               } else {
                 $('div.error').show();
               }
             }
           });
           return false;
         });
       });
 --

 And here is my json array in PHP:
 --
 $message = $_POST['email'];

 if($message != '') {
   mail('some-em...@email.com', 'Ajax test', $message);
   $json_data = array('result' = 1).} else {

   $json_data = array('result' = 0, 'error' = 'This is an error').

 }

 json_encode($json_data);
 --

 I'm obviously not accessing del.result correctly because $
 ('div.error').show(); is always executed regardless of the value of
 result.  Where am I going wrong?

 Thanks in advance,

 Rob.

 On Jan 4, 2:41 pm, donb falconwatc...@comcast.net wrote

[jQuery] How to handle responses from PHP with $.ajax()

2009-01-04 Thread rob303

Hi,

I'm new to ajax and jquery but I'm not new to PHP.  The following
example seems to work okay to a point but I can't figure out how to
handle data validation errors generated in my PHP.

In my example I want to post some data to a script called ajax.php.
That script will check the data for validity and then return true or
false depending on the outcome of the checks. It will also set an
appropriate error message.

How can I handle the returned data and display an error message if
needed in ajax?

--
HTML / Ajax - test.php
--
?php

require_once(includes.php);

?
html
  head
script src=js/jquery.js type=text/javascript/script
script type=text/javascript
  $(document).ready(function(){
$(form#submit).submit(function() {
  var email = $('#email').attr('value');
  $.ajax({
type: POST,
url: ajax.php,
data: email=+ email,
success: function(del){
  $('form#submit').hide();
  $('div.success').fadeIn('medium');
  // what if the data failed validation in PHP?
  // we need to show 'div.error.
}
  });
  return false;
});
  });
/script
  /head
  body
form id=submit method=post
  Email:
  input id=email class=text name=email size=20
type=text /
  input type=submit value=send mail /
/form
div class=success style=display:none;
  Email sent.
/div
div class=error
  ?php echo $userError; ?
/div
  /body
/html

--
PHP - ajax.php
--
?php

require_once(includes.php);

$message = $_POST['email'];

if($message != '') {
  mail('some-em...@email.com', 'Ajax test', $message);
  return 1;
} else {
  $userError = Please enter your email address;
  return 0;
}

?

I've been searching the web for an answer but can't find one
anywhere!  Any help would be greatly appreciated.


[jQuery] Re: How to handle responses from PHP with $.ajax()

2009-01-04 Thread rob303

After a little more twiddling ... This works:

$(document).ready(function(){
$(form#submit).submit(function() {
  var email = $('#email').attr('value');
  $.ajax({
type: POST,
url: ajax.php,
data: email=+ email,
success: function(res){
  if(res == {\result\:1}) {
$('form#submit').hide();
$('div.error').hide();
$('div.success').fadeIn('medium');
  } else {
$('div.error').show();
  }
}
  });
  return false;
});
  });

The json object contains what I need but I can only test it as if it
were a string.  res.result is undefined. Why?

Thanks in advance for any help!

Rob.

rob303 wrote:
 Hi again,

 I tried that but got the same results.

 if(res.result == '1') {
   $('form#submit').hide();
   $('div.success').fadeIn('medium');
 } else {
   $('div.error').show();
 }

 if(res.result == 1) {
   $('form#submit').hide();
   $('div.success').fadeIn('medium');
 } else {
   $('div.error').show();
 }

 res.result is always false even though firebug says the response is
 {result:1}.

 Rob.



 On Jan 4, 7:01�pm, donb falconwatc...@comcast.net wrote:
  On another thread, someone pointed out to me that json_encode was
  supposed to 'know' if the data values were numeric or string and only
  quote the latter. �That was not my experience, and perhaps not yours,
  either. �Try '1' as the value you compare to instead of 1.
 
  On Jan 4, 1:05�pm, rob303 r...@cube33.com wrote:
 
   Interestingly, in the Firebug console I'm seeing the correct
   responses:
 
   {result:1}
 
   or
 
   {result:0}
 
   How can I access these inside my $.ajax() call?
 
   Many thanks again for all the help!
 
   Rob.
 
   On Jan 4, 5:57�pm, rob303 r...@cube33.com wrote:
 
Yes, the missing semicolons are an error in the post. I tried to echo
the json_encode() call but I still can't get it to work. If I leave
the email input blank no email is sent. If I enter a string the email
is sent. The 'div.error' is always displayed regardless what's posted.
 
Here's my full code again:
 
--
HTML / Ajax
--
?php
 
require_once(../inc/site_config.php);
 
require_once(SITE . /includes.php);
?
html
� head
� � � � script src=js/jquery.js type=text/javascript/script
� � script type=text/javascript
� � � $(document).ready(function(){
� � � � $(form#submit).submit(function() {
� � � � � var email = $('#email').attr('value');
� � � � � $.ajax({
� � � � � � type: POST,
� � � � � � url: ajax.php?v=1,
� � � � � � data: email=+ email,
� � � � � � success: function(res){
� � � � � � � if(res.result == 1) {
� � � � � � � � $('form#submit').hide();
� � � � � � � � $('div.success').fadeIn('medium');
� � � � � � � } else {
� � � � � � � � $('div.error').show();
� � � � � � � }
� � � � � � }
� � � � � });
� � � � � return false;
� � � � });
� � � });
� � /script
� /head
� body
� � � form id=submit method=post
� � � � Email:
� � � � input id=email class=text name=email size=20
type=text /
� � � � � � input type=submit value=send mail /
� � � � � /form
� � � div class=success style=display:none;
� � � � Email sent.
� � � /div
� � � div class=error style=display:none;err/div
� /body
/html
 
--
PHP
--
?php
 
require_once(includes.php);
 
$message = $_POST['email'];
 
if($message != '') {
� mail('some-em...@email.com', 'Ajax test', $message);
� $json_data = array('result' = 1);} else {
 
� $json_data = array('result' = 0);
 
}
 
echo json_encode($json_data);
 
?
$message = $_POST['email'];
 
if($message != '') {
� mail('@cube33.com', 'Ajax test', $message);
� $json_data = array('result' = 1);} else {
 
� $json_data = array('result' = 0);
 
}
 
echo json_encode($json_data);
 
?
--
On Jan 4, 5:44�pm, donb falconwatc...@comcast.net wrote:
 
 You must 'echo' the JSON output. �Also you indicate periods ending
 code lines, instead of semicolons but perhaps that's just an error in
 your post, not the actual code?
 
 On Jan 4, 10:38�am, rob303 r...@cube33.com wrote:
 
  Hi,
 
  Many thanks for the help. �I had a go at implementing what you
  suggested but I'm clearly still missing something.
 
  Here is my $.ajax() call:
  --
  $(document).ready(function(){
  � � � � $(form#submit).submit(function() {
  � � � � � var email = $('#email').attr('value');
  � � � � � $.ajax({
  � � � � � � type: POST,
  � � � � � � url: ajax.php,
  � � � � � � data: email=+ email,
  � � � � � � success: function(del){
  � � � � � � � if(del.result == 1

[jQuery] Re: How to handle responses from PHP with $.ajax()

2009-01-04 Thread rob303

I found the problem.  I was missing the dataType option:

$(document).ready(function(){
$(form#submit).submit(function() {
  var email = $('#email').attr('value');
  $.ajax({
type: POST,
url: ajax.php,
data: email=+ email,
dataType: json,
success: function(res){
  if(res.result == 1) {
$('form#submit').hide();
$('div.error').hide();
$('div.success').fadeIn('medium');
  } else {
$('div.error').show();
  }
}
  });
  return false;
});
  });

It works just fine now.

Cheers,

Rob.

On Jan 4, 10:12 pm, rob303 r...@cube33.com wrote:
 After a little more twiddling ... This works:

 $(document).ready(function(){
         $(form#submit).submit(function() {
           var email = $('#email').attr('value');
           $.ajax({
             type: POST,
             url: ajax.php,
             data: email=+ email,
             success: function(res){
               if(res == {\result\:1}) {
                 $('form#submit').hide();
                 $('div.error').hide();
                 $('div.success').fadeIn('medium');
               } else {
                 $('div.error').show();
               }
             }
           });
           return false;
         });
       });

 The json object contains what I need but I can only test it as if it
 were a string.  res.result is undefined. Why?

 Thanks in advance for any help!

 Rob.

 rob303 wrote:
  Hi again,

  I tried that but got the same results.

  if(res.result == '1') {
    $('form#submit').hide();
    $('div.success').fadeIn('medium');
  } else {
    $('div.error').show();
  }

  if(res.result == 1) {
    $('form#submit').hide();
    $('div.success').fadeIn('medium');
  } else {
    $('div.error').show();
  }

  res.result is always false even though firebug says the response is
  {result:1}.

  Rob.

  On Jan 4, 7:01 pm, donb falconwatc...@comcast.net wrote:
   On another thread, someone pointed out to me that json_encode was
   supposed to 'know' if the data values were numeric or string and only
   quote the latter. That was not my experience, and perhaps not yours,
   either. Try '1' as the value you compare to instead of 1.

   On Jan 4, 1:05 pm, rob303 r...@cube33.com wrote:

Interestingly, in the Firebug console I'm seeing the correct
responses:

{result:1}

or

{result:0}

How can I access these inside my $.ajax() call?

Many thanks again for all the help!

Rob.

On Jan 4, 5:57 pm, rob303 r...@cube33.com wrote:

 Yes, the missing semicolons are an error in the post. I tried to echo
 the json_encode() call but I still can't get it to work. If I leave
 the email input blank no email is sent. If I enter a string the email
 is sent. The 'div.error' is always displayed regardless what's posted.

 Here's my full code again:

 --
 HTML / Ajax
 --
 ?php

 require_once(../inc/site_config.php);

 require_once(SITE . /includes.php);
 ?
 html
 head
 script src=js/jquery.js type=text/javascript/script
 script type=text/javascript
 $(document).ready(function(){
 $(form#submit).submit(function() {
 var email = $('#email').attr('value');
 $.ajax({
 type: POST,
 url: ajax.php?v=1,
 data: email=+ email,
 success: function(res){
 if(res.result == 1) {
 $('form#submit').hide();
 $('div.success').fadeIn('medium');
 } else {
 $('div.error').show();
 }
 }
 });
 return false;
 });
 });
 /script
 /head
 body
 form id=submit method=post
 Email:
 input id=email class=text name=email size=20
 type=text /
 input type=submit value=send mail /
 /form
 div class=success style=display:none;
 Email sent.
 /div
 div class=error style=display:none;err/div
 /body
 /html

 --
 PHP
 --
 ?php

 require_once(includes.php);

 $message = $_POST['email'];

 if($message != '') {
 mail('some-em...@email.com', 'Ajax test', $message);
 $json_data = array('result' = 1);} else {

 $json_data = array('result' = 0);

 }

 echo json_encode($json_data);

 ?
 $message = $_POST['email'];

 if($message != '') {
 mail('@cube33.com', 'Ajax test', $message);
 $json_data = array('result' = 1);} else {

 $json_data = array('result' = 0);

 }

 echo json_encode($json_data);

 ?
 --
 On Jan 4, 5:44 pm, donb falconwatc...@comcast.net wrote:

  You must 'echo' the JSON output. Also you indicate periods ending
  code lines, instead of semicolons but perhaps that's just an error 
  in
  your post, not the actual code?

  On Jan 4, 10:38 am, rob303 r...@cube33.com wrote:

   Hi