[ACCEPTED]-use JQuery to get siblings-jquery
Your issue stems from your approach. Calling 19 a function directly won't do what you're 18 expecting, which is to have a jquery object 17 representing the <a> tag. Rather than 16 call a function directly you can register 15 a function to respond to a click
event on the 14 <a>.
First, give your link an id:
<a href="#" id="appendSelect">append</a>
Then 13 use replace your appendField()
function with a jQuery 12 select that responds to click
$(document).ready(function() {
$("#appendSelect").click(function() {
var $thatInput = $(this).siblings("input");
var $selectValue = $(this).siblings("select").val();
$thatInput.val($selectValue);
})
});
With this approach 11 $(this)
will represent your <a>.
You can see 10 what I'm talking about to a greater depth 9 by using a javascript debugging console 8 (chrome has one by default, and you can 7 use Firebug on Firefox). Try your original 6 function based approach again and add a 5 console.log($(this));
statement. You should see it printing out 4 a DOMWindow object. Now put the same log 3 statement in the click
function and you'll see 2 that jQuery has given you a $(this) representing 1 what you expected it to be.
try:
$(this).parent().children("input:first").val();
0
The appendfield method does not access to 1 $(this).
Here is the working code: http://jsfiddle.net/NBf4d/2/
use .children() or .find()
.children only 2 looks for direct children of the parent, find 1 looks at all levels below the parent.
$('.ms-formbody').find('select').val();
This will only work for these IDs, but you 1 can easily change them:
$('#ctl00_PlaceHolderMain_dlFields_ctl00_txtSource').val($('#ctl00_PlaceHolderMain_dlFields_ctl00_ddlSourceFields').val());
try this...
$(this).parent().find('input:first').val(selectedOptionValue);
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.