My question is similar to this: How to get the value of a text field in a label using jquery , but I'm trying to do the opposite: I am trying to get the value of a label in a text field. I thought it would be easy to switch elements in the code, but this is not the case, apparently. I also looked at some of the questions presented in the section โQuestions that may already have your answerโ below my name, but did not find what helped me (maybe the solution was in one of them, but I just did not understand this .. .).
Here is my html table:
<table id="tblBranchDetails"> <tr> <td width="120px">Branch:</td> <td id="branchName" class="branchData"> <label id="lblBranchName"></label> <input type="text" id="txtBranchName" /> </td>...
As the above post noted, this does not work:
$('input#hdnBranchName').val() = $('label#lblBranchName').text();
I tried these:
$('input#txtBranchName').html($('label#lblBranchName').val()); $('input#txtBranchName').text($('label#lblBranchName').val());
None of them worked. So I tried to check if I could not select the text box correctly:
$('table#tblBranchDetails input#txtBranchName').html($('label#lblBranchName').val()); $('table#tblBranchDetails input#txtBranchName').text($('label#lblBranchName').val());
But not one of them worked.
How to do it and how to find out more: why I donโt think that an explicit method works?
Thanks!
jquery label textbox
marky
source share