1

I have form that has numerous checkboxes and input field. Each 'pair' of checkbox & input have the same name, but the checkboxes name is prefixed with u_

eg:

<input type='checkbox' name='u_id'><input type="text" name="id" placeholder="ABC123">
<input type='checkbox' name='u_name'><input type="text" name="name" placeholder="Martin">

I'm trying to work out how to disable in the input field and set it's placehold to 'disabled' when the associated checkbox is ticket.

If it is then unticked, rest the field and it's placeholder.

So far I've got :

if ($('[name^="u_"]').is(':checked')) {

}

But I'm not sure where to go now..

Can you help ?

Thanks

1
  • please post a jsfiddle so it will be very easy. Commented Mar 6, 2015 at 9:22

1 Answer 1

2
$('[name^="u_"]').change(function(){
    if($(this).is(":checked"))
    {
        $(this).next("input").attr("disabled",true);
    }
    else
    {
        $(this).next("input").attr("disabled",false);
    }
});

Demo

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

1 Comment

Thanks this works, well.. can it be expanded to work on INPUT and/or SELECT ?

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.