0

i'm trying to change the value of an text input to no if checked or yes if not checked, this with a checkbox but i cant seem to get it working..

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


$(function(){
$('#checkbox').change(function() {
    $("#text").val(($(this).is(':checked')) ? "yes" : "no");
});
});

Demo: http://jsfiddle.net/YJRQp/

is there something i miss here? please advise.

3
  • 1
    JQuery isn't included in that fiddle... Commented Nov 20, 2013 at 20:42
  • 1
    It works fine. Seems you forget to include jQUery. Commented Nov 20, 2013 at 20:42
  • 1
    You didn't load jquery! No wonder that it did not work... see here: http://jsfiddle.net/YJRQp/1/ Commented Nov 20, 2013 at 20:43

2 Answers 2

1

You just need to include jQuery in your fiddle. Theres a dropdown on the left for libraries.

Sign up to request clarification or add additional context in comments.

1 Comment

i feel ashamed for missing that ! sorry
0

This should work

$(document).ready(function(){
    $("#checkbox").click(function(){
        if ($(this).is(':checked'))
        {
            $("#text").val("Yes");
        }
        else
        {
            $("#text").val("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.