My question is similar to this: How to get textbox value into label using jquery, but I'm trying to do opposite: I'm trying to get the value of a label into a into a textbox. I thought it'd be a simple matter of switching the elements in the code, but that's not the case, apparently. I also did take a look at some of the questions presented in the "Questions that may already have your answer" section below my title, but didn't find something that helped me (maybe the solution was in one of them, but I just didn't understand it...).
Here's my table's html:
<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 author of the post above noted, this doesn't work:
$('input#hdnBranchName').val() = $('label#lblBranchName').text();
I've tried these:
$('input#txtBranchName').html($('label#lblBranchName').val());
$('input#txtBranchName').text($('label#lblBranchName').val());
Neither of those worked. So I tried to see if maybe I wasn't selecting the textbox correctly:
$('table#tblBranchDetails input#txtBranchName').html($('label#lblBranchName').val());
$('table#tblBranchDetails input#txtBranchName').text($('label#lblBranchName').val());
But neither of those worked either.
How do I do this, and as a matter of learning more: why doesn't what I would assume to be the obvious method work?
Thanks!