Gowthami Bethanabotla
Gowthami Bethanabotla

Reputation: 11

Trying to access input hidden element using sibling() - jQuery method, but couldn't

I have 2 input elements of type text and hidden.

<c:forEach items="seaList" var="sList" varStatus="myIndex"> 
               <td style="font-size: 9pt">
                    <input name="CM_name" id="CM_name${myIndex.index}" type="text"  value="${sList.cm_id}"  class= "Face" placeholder="Search " autocomplete="off" onclick="searchMe(this.id)">
                    <input type="hidden" name="CM_name1" value="${sList.cm_id}" />
                </td>
                <td style="font-size: 9pt">
                    <input name="BOM_name" id="BOM_name${myIndex.index}" type="text"  value="${sList.bom_id }" class= "Face" placeholder="Search" autocomplete="off" onclick="searchMe(this.id)">
                    <input type="hidden" name="BOM_name1" value="${sList.bom_id }" />
                </td> 
</c:forEach>

On click of text type element, hidden element's value also should be set. So, I am trying to use the below jQuery script

function searchme(idx){

      Face.init(

            $('#'+idx)[0],
            {
            faces: {
                enabled: true,
                onclick: function(person) {
                  var i= "[email protected]";
                  var s=$(this).siblings('input:hidden').val(i); 
                  alert(s);                   
                  return i;

                }
            }
        });          

}

with "$(this).siblings('input:hidden').val(i); " line, nothing is happening atleast I am not able to get the existing value to a variable by "var x= $(this).siblings('input:hidden').val();" Can anyone please help me out in changing the hidden input value in jQuery ?

Upvotes: 0

Views: 193

Answers (2)

Milan Chheda
Milan Chheda

Reputation: 8249

So you are tying to populate the hidden field based on the value of the visible field. Below code should help you get that:

$(".Face").on('keyup', function(){
   $(this).next('input').val($(this).val())
});

Basically, this code gets triggered whenever you enter anything in the visible field, and same value would be in the hidden field too. Try and let us know.

Upvotes: 0

Ankit Agarwal
Ankit Agarwal

Reputation: 30739

You can try this

var s=$(this).find('input[type=hidden]').val(i); 

Upvotes: 1

Related Questions