Here is my html tag,
<asp:Label runat="server" ID="rdPayOutstanding"></asp:Label><br />
i wish to retrieve the value which is within the span tags and display it in a textbox, I have written the code below but it doesnt seem to work.
Can anyone help with what the issue with my code is ?
$(document).ready(function () {
var amount = $('#rdPayOutstanding').text().toString();
console.log(amount);
$('.textfield').val(amount);
$('.jsPayOutstanding').click(function () {
$('.textfield').val(amount);
});
$('.jsPaySomeBalance').click(function () {
// alert('yes');
$('.textfield').val('');
});
});
The problem is that you are using ASP.NET and when the controls render the ASP.NET engine modifies the ID of the resulting HTML elements.
You can add an attribute ClientIDMode to get the “correct” id:
Another approach is to use the attribute CssClass and select by class instead: