1

First I alert this, and alert 'undefined':

alert($("input[name='searchManagers']:checked").val());

But when I try this, why alert 'no':

if($("input[name='searchManagers']:checked").val() == 'undefined')
    alert('yes')
else
    alert('no')

That fix my problem:

if(typeof $("input[name='searchManagers']:checked").val() == 'undefined')
    alert('yes')
else
    alert('no')
4
  • please show us your code in a fiddle Commented Sep 21, 2012 at 11:41
  • 1
    Change it to if(typeof $("input[name='searchManagers']:checked").val() == 'undefined') - what happens now? Commented Sep 21, 2012 at 11:42
  • try this :) some html could help btw :) $("input[name='searchManagers']").is( ':checked' ); Commented Sep 21, 2012 at 11:42
  • Try this on: [stackoverflow.com/questions/426258/… [1]: stackoverflow.com/questions/426258/… Commented Sep 21, 2012 at 11:45

6 Answers 6

3

The second one you are comparing to a string instead of the undefined type.

Try this:

if($("input[name='searchManagers']:checked").val() == undefined)

or:

if(typeof $("input[name='searchManagers']:checked").val() == 'undefined')
Sign up to request clarification or add additional context in comments.

Comments

2

Use:

$("input[name='searchManagers']").is(":checked")

Comments

1

Because undefined != 'undefined' If you were to modify your code

  if($("input[name='searchManagers']:checked").val() == undefined)
    alert('yes')
  else
    alert('no')

Then it should work

Comments

1

change 'undefined' to undefined without quotes

if($("input[name='searchManagers']:checked").val() == undefined)

Comments

0

Please make sure set the id and name property in check box. And try below the code.

if(!$("input[name='searchManagers']:checked").val()){
    alert('Plase select the searchManagers');
    return false;
}

Comments

0

Please make some changes and find the output.

  if ($("input[name='searchManagers']").is(':checked'))
  alert('yes');
  else
  alert('no');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.