0

I have an input field defined like this:

<form class="form-inline">
    <input type="text" title= "language" class="input-block-level" placeholder="Insert Languages"/>
</form>

I wrote up a mock jQuery script just to put the word "Yes" based on whether a checkbox has been checked. Look here:

$(document).ready(function () { 
    $('#checkbox').change(function(){
        if ($('#checkbox').is(':checked')) { 
            $("input[Title='language']").val("Yes"); 
        }
    }); 
}); 

However, it's not working and there are no errors in the console. I'm new to jQuery and am having a hard time understanding where exactly to put it, and how $(document).ready(function () { functions, so that may be the problem.

The non-working example can be seen here http://dreaminginswahili.com/admin/mapv4.html on the languages pane.

2
  • Why can't you just use the same code that you're using on the other tabs? Commented Jul 18, 2013 at 15:59
  • Where is your checkbox? Can you add that to your html? Commented Jul 18, 2013 at 16:00

1 Answer 1

3

$('#checkbox') looks for an element with id="checkbox", like this

<input type="text" id="checkbox" />

but you don't have any in your html, so nothing happens.

If you have checkbox elements like <input type="checkbox" />, then you can select the checkboxes like this:

$(':checkbox')

and you can select the "checked" boxes like this:

$(':checkbox:checked')
Sign up to request clarification or add additional context in comments.

3 Comments

This works. Accepting in 9 minutes. Question- how would I get the textbook to append the value of the checkbox ID with a comma for each checked checkbox? And then remove that once the checkbox is unchecked?
This is actually the example given in the documentation! api.jquery.com/map
You're wonderful. You've saved me so much headache. Thank you

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.