use JQuery to get siblings -


i'm trying tag below grab value select , paste input.

<td class="ms-formbody" style="width:385px">     <input name="ctl00$placeholdermain$dlfields$ctl00$txtsource" type="text" id="ctl00_placeholdermain_dlfields_ctl00_txtsource" class="ms-input" />     <select name="ctl00$placeholdermain$dlfields$ctl00$ddlsourcefields" id="ctl00_placeholdermain_dlfields_ctl00_ddlsourcefields" class="ms-input">         <option value="some field name 1">some field name 1</option>         <option value="some field name 2">some field name 2</option>         <option value="some field name 3">some field name 3</option>         <option value="some field name 4">some field name 4</option>     </select>     <a href="javascript: appendfield();">append</a> </td> 

i can't seem figure out how grab siblings. tried $(this).siblings("input").val() errored webpage error 'parentnode.firstchild' null or not object.

tried $(this).prev().prev().val() , comes undefined. what's best way grab these things?

thanks, david

your issue stems approach. calling function directly won't you're expecting, have jquery object representing <a> tag. rather call function directly can register function respond click event on <a>.

first, give link id:

<a href="#" id="appendselect">append</a> 

then use replace appendfield() function jquery select responds click

$(document).ready(function() {   $("#appendselect").click(function() {     var $thatinput = $(this).siblings("input");     var $selectvalue = $(this).siblings("select").val();     $thatinput.val($selectvalue);   }) }); 

with approach $(this) represent <a>.

you can see i'm talking greater depth using javascript debugging console (chrome has 1 default, , can use firebug on firefox). try original function based approach again , add console.log($(this)); statement. should see printing out domwindow object. put same log statement in click function , you'll see jquery has given $(this) representing expected be.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -