This is untested, but maybe it will get you on the right path.
$('div.A//input:checkbox').each(function(){}
$(this).click(function(){
$(this).siblings("input:text").attr("value",function() {return
(this.checked) ? "message1" : "message2" } );
});
);
bdanchilla wrote:
>
> Hello,
> I am using jquery with a CMS (drupal). I have written code which
> generates html output like the following pseudocode
>
> <div class="A">
> <input type="checkbox" name="A_check_1" ...>
> <input type="text" name="A_text_1" value="">
> </div>
> <div class="A">
> <input type="checkbox" name="A_check_2" ...>
> <input type="text" name="A_text_2" value="">
> </div>
> ...
> <div class="A">
> <input type="checkbox" name="A_check_n" ...>
> <input type="text" name="A_text_n" value="">
> </div>
>
>
> I want a check/uncheck to change the content of the textbox. I have tried
> to write javascript like the following:
>
> $("div.A").each(
> function(){
> $(this).find("[EMAIL PROTECTED]@name^=A_").click(){
> function(){
> if(this.checked){
> $(this). find("[EMAIL PROTECTED]@name^=A_]").val("msg
> 1");
> }else{
> $(this). find("[EMAIL PROTECTED]@name^=A_]").val("msg
> 2");
> }
> }
> )
> }
> );
> }
> );
>
> The problem is that I can find the first element (the checkbox) but not
> the textfield for each division, since the second search starts from the
> first element. I am new to jquery. Am I supposed to use end() somewhere
> and store the checkbox reference in a variable of some sort? Should I use
> parents() or some other function? Any help is appreciated.
>
--
View this message in context:
http://www.nabble.com/using-end%28%29%2C-or-storing-queries-as-variables-tf3269753.html#a9092114
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/