tags:

views:

66

answers:

1
<select onchange="$(self).siblings('input[type=text]').val( $(self).val() ); $(self).siblings('input[type=checkbox]').attr('checked','checked')">

that does not work

before the select box, there are these inputs (examples):

<input type="text" value="" id="product[14][value]" name="product[14][value]">
<input type="checkbox" value="1" id="product[14][enabled]" name="product[14][enabled]">

after debugging in firebug, i found that it is in fact finding the siblings, and the part that is failing is filling the text field with the select's value:

.val( $(self).val() ); 

what's wrong with it? thanks!

+2  A: 

Use $(this), not $(self). self refers to the window property window.self (which is in fact the window object.

Andy E
It is often used, though, as an alias for `this` inside closures. At least by me.
MvanGeest
@MvanGeest: yes, you see `self` used as *storage* for `this` in a lot of online examples and it's probably what confused the OP.
Andy E
Storage... I believe the best explanation is that "`self` will reference the same object that `this` referenced". It's not a value-based action. I agree with your point.
MvanGeest