The following function adds a new text input after every checkbox when it is checked, and removes the text input when the checkbox is unchecked. The name of the text input is based on the name of the checkbox.
jQuery(function($){
var key = 'checkbox-master';
$('input:checkbox').click(function(){
var self = $(this);
var next = self.next();
if (this.checked){
if (next.data(key)!=this){
var n = this.name+'-text';
self.after($('<input type="text" name="'+n+'">').data(key,this););
}
}else{
if (next.data(key)==this) next.remove();
}
});
});
I wonder if you really want this, however, instead of just dynamically showing and hiding some pre-created text inputs that have the names you want. That would be cleaner, assuming the text inputs are always immediately following the checkboxes in code:
jQuery(function($){
$('input:checkbox').click(function(){
$(this).next()[this.checked ? 'show' : 'hide']();
});
});