1

Usually they make another thing: enable/disable text input field when checkbox checked/unchecked, but i need enable group of checkboxes (weekdays) only when user entering some text in text field (Start date). So checkboxes must still disable while user not type Start date in input field.

I think that I need back action than here: http://jsfiddle.net/H8VPY/11/

Please help me choose right jquery event.

2 Answers 2

2

You can use prop() method and keyup event handler. Try the following:

$('input[name=other_name]').keyup(function(){
    if (this.value.length > 0) {
       $('input[name="others"]').prop('disabled', false)
    } else {
       $('input[name="others"]').prop('disabled', true)      
    }
})

DEMO

or as Esailija correctly suggests you can use shorter version:

$('input[name=other_name]').keyup(function(){
     $('input[name="others"]').prop('disabled', !this.value.length)
})
Sign up to request clarification or add additional context in comments.

3 Comments

$('input[name="others"]').prop('disabled', !this.value.length ) would work as well
Fantastic, thank you Raminson and Esailija, your answer solved problem. Now I want to color this text input with red (add some css class) when user try to check checkbox and can't do it 'cause it is disabled. or just hint some message near checkbox. Or I can't do it because checkbox is disabled and all events will not work with it?
Thank you again Raminson. I'll add css to <span> and it'll be cool!
0

add a class and disable to your checkboxes;

<checkbox class="checkbox_class" disabled >

on your text box;

<input type="text" onkeyup="javascript: if($(this).val() != '') $('.checkbox_class').enable()" >

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.