[jQuery] Re: If radio button checked - do stuff

2009-12-30 Thread MorningZ
i think the problem is with your selector (and this is above and
beyond the psuedo error

$(form input[name=setting1]:radio).filter(':checked').click

that will only bind the click event to checked radio buttons, which
on page load wouldn't be the desired behaviour

I've fallen for event delegation lately, and taking your HTML, this
would work nicely  :-)

super quick example using your HTML
http://jsbin.com/ajaju/edit (code)
http://jsbin.com/ajaju (run)


On Dec 30, 11:03 am, Silver 8800gt...@gmail.com wrote:
 Hey all,

 I think I'm close, but I keep getting the errors ( Unkonw pseude-class
 or pseude-elmemt 'radio').

 All I need is if the user clicks a radio button for the right if
 statement to run and send the variables to the dq_process php file.

 $(form input[name=setting1]:radio).filter(':checked').click(function
 () {
     if ( $(this).val() == 'home_fy' )
             $.post(dq_process.php, { q: 1, r: 13300 } );
     else if ( $(this).val() == 'home_by' )
             $.post(dq_process.php, { q: 1, r: 24400 } );
     else
             $.post(dq_process.php, { q: 1, r: 0 } );

 });

 ol class=answers
                 liinput type=radio name=setting1 value=home_fy  / 
 Home –
 front yard/li
                 liinput type=radio name=setting1
 value=home_by  / Home – back yard/li
                 liinput type=radio name=setting1
 value=cottage  / Cottage/li
 /ol

 Any help would be great. Thanks


[jQuery] Re: If radio button checked - do stuff

2009-12-30 Thread Silver
Thanks guys ...

I got it working now ..

 $(document).ready(function(){
/* S Q1 */
 $('input[name=1_setting]:radio').click(function () {
 if ( $(this).val() == 'home_fy' ) { $.post(dq_process.php, { q: 1,
r: 13300 } ); }
 else if ( $(this).val() == 'home_by' ) { $.post(dq_process.php,
{ q: 1, r: 24400 } ); }
 else if ( $(this).val() == 'cottage' ) { $.post(dq_process.php,
{ q: 1, r: 24400 } ); }
 else if ( $(this).val() == 'commercial' ) { $.post(dq_process.php,
{ q: 1, r: 24400 } ); }
 else if ( $(this).val() == 'other' ) { $.post(dq_process.php, { q:
1, r: 24400 } ); }
 });
/* E Q1 */
});

On Dec 30, 12:53 pm, brian zijn.digi...@gmail.com wrote:
 You have some redundancy there. Selecting on ':radio' is unnecessary
 because you're also selecting for the element name. And the ':checked'
 is no good because that limits this to elements that have already been
 checked. That's likely not the desired behaviour. Try:

 $('form input[name=setting1]').click(function() { ... });

 On Wed, Dec 30, 2009 at 11:03 AM, Silver 8800gt...@gmail.com wrote:
  Hey all,

  I think I'm close, but I keep getting the errors ( Unkonw pseude-class
  or pseude-elmemt 'radio').

  All I need is if the user clicks a radio button for the right if
  statement to run and send the variables to the dq_process php file.

  $(form input[name=setting1]:radio).filter(':checked').click(function
  () {
     if ( $(this).val() == 'home_fy' )
             $.post(dq_process.php, { q: 1, r: 13300 } );
     else if ( $(this).val() == 'home_by' )
             $.post(dq_process.php, { q: 1, r: 24400 } );
     else
             $.post(dq_process.php, { q: 1, r: 0 } );
  });

  ol class=answers
                 liinput type=radio name=setting1 value=home_fy  / 
  Home –
  front yard/li
                 liinput type=radio name=setting1
  value=home_by  / Home – back yard/li
                 liinput type=radio name=setting1
  value=cottage  / Cottage/li
  /ol

  Any help would be great. Thanks