Re: [jQuery] using end(), or storing queries as variables

2007-02-21 Thread Daemach

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
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] using end(), or storing queries as variables

2007-02-21 Thread Daemach

OK I rewrote and tested it with your pseudocode.  This is kind of loose, but
it does work. 


$('div.A/input:checkbox').each(function(){
$(this).click(function(){

$(this).siblings(input:text).attr(value,function() 
{return
($(this).siblings(input:checkbox).attr(checked)) ? message1 :
message2 } );
});
});

If you have a predefined naming scheme, such as id=someprefix_someid it
could tighten things up a bit.  You can then use 

$('div.A/input:checkbox').each(function(){
$(this).click(function(){
message = (this.checked) ? message1 : message2;

$('#A_text_'+this.id.split(_)[2]).attr(value,message);
});
}); 




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#a9092783
Sent from the JQuery mailing list archive at Nabble.com.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/