2

So, I'm trying to make sure a button is disabled to prevent a user from saving data from form field entries whenever two conditions are met:

  1. The checkbox is checked
  2. There's nothing inside the form field in question ( #read_return_response_rate_ids )

This is what I have to that end:

$('body').on("change","#tab3 #read_return_response_rate_ids", function(){
  if ($(this).is('')) && ($('input:checkbox').is(':checked')) {
    $('.create_read_btn').attr('disabled', 'disabled');
  } else {
    $('.create_read_btn').removeAttr('disabled');
  }
});

The error it's giving me in the console is totally useless towards debugging purposes.

Uncaught SyntaxError: Unexpected token /

It's my thought that this is where the problem exists:

  if ($(this).is('')) && ($('input:checkbox').is(':checked'))

Basically, I don't think I can have multiple selectors as I have them structured, but I don't know. Does anyone have any thoughts on why this is returning an error? I confirmed that this code block is where the error originates by selectively commenting out other blocks of code and whittling it down to this one.

4
  • Check your parentheses. Commented Aug 20, 2015 at 18:45
  • The parenthese of your if are wrong Commented Aug 20, 2015 at 18:45
  • And that $(this).is('') is really suspect. is expects you to have something in that string. Commented Aug 20, 2015 at 18:45
  • How would I set it up so that it would check to see if there's nothing inside a form input then? I figured checking for an empty string would be the way to go? Commented Aug 20, 2015 at 19:01

2 Answers 2

1

There are syntax errors (parenthesis chars note required):

Change:

if ($(this).is('')) && ($('input:checkbox').is(':checked')) {

by

if ($(this).is('') && $('input:checkbox').is(':checked')) {
Sign up to request clarification or add additional context in comments.

Comments

1

The argument to .is() must be a selector or jQuery collection; it tests whether the specified element matches the selector or is the same set of objects. If you want to test whether an input field is empty, you need to use .val() to get the value.

if ($(this).val() == '' && $('input:checkbox').is(':checked')) {

1 Comment

Awesome! Thanks so much!

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.