Inside your .each() you need to select the text input in relation to
the matched checkbox. Also, you can't set a DOM property value on a
jQuery object.
This should work:
$(':text~:checkbox').each(
function(){
if(!this.checked) {
$(this).prev()
.css('background-color','yellow')
[0].disabled = true;
}
}
);
You could also replace [0].disabled = true with .attr('disabled', true)
--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Oct 1, 2009, at 11:31 AM, Julien wrote:
Hi,
One of my HTML forms uses pairs of "checkbox/text" inputs.
Each checkbox is printed on the left of the text input, but is written
before that field as it must be justified on the right (float:right).
<li>
<input name="footer_company" type="text" style="float:right;" />
<input name="footer_company_checkbox" type="checkbox"
checked="checked">Company name :</input>
</li>
I would like to disable each text input for which the corresponding
checkbox doesn't have the "checked" status.
I could retrieve the checkboxes that are preceded by a text field and
find which ones are in unselected mode.
But I was then unable find for each unchecked checkbox the preceding
text field so that I can disable it.
The ".disabled=true" also does not disable any text field.
$(':text~:checkbox').each(
function(){
if(!this.checked) {
$(':text').css('background-color','yellow'); // This works but
selects all text inputs.
$(':text').disabled=true; // This does not work.
}
}
);
Thanks for any help.
Julien