Marcus H Marcus H - 3 months ago 9
jQuery Question

Retreive value from input field, inside table TD when selected

I am wondering if there is some way to retreive a value from an input field, inside a TD when this TD is being selected (clicked).

I managed to get 1 of the values out, but it didnt change when I pressed the other row.

for example, here is my JSP, which leads to 2 TD's :

<div class="col-md-6">
<table class="table fixed">
<th>Choose what account you want to login to</th>
<td align="right"><strong></strong></td>
<c:forEach var="i" begin="0" end="${roleList.getSize() -1}">
<tbody id="extend">
<tr data-toggle="collapse123" class="clickableRow spaceUnder" nowrap="true" data-target=".demo1" id="1">
<td class="AlignLeft" nowrap="true" style="border-right: 0px;">
<label for="important"style="display: inline !important">${roleList.getFirstName(i)} ${roleList.getLastName(i)}</label>
<td align="right" class="AlignRight" style="border-left: 0px;">
<input type="hidden" id ="roleId" name="chosenRole" value="${roleList.getClientId(i)}">

<input type="hidden" id ="roleClicked" name="roleClicked" value="">

And here is my javascript/jquery:

$( document ).ready(function() {

$("#extend td").click(function () {

How do i select the clicked TD's inputfield's value??


Edit: I'm Back was correct, allthough i had to move my input field from the second TD to the first one which is no problem at all for me (its hidden anyways) Thanks for the help


You need to use Check this link

$('#extend td').click(function(){
    var roleid = $(this).find('input').val();

Instead of - The val() method returns or sets the value attribute of the selected elements.