i am trying to change text of label and textbox text on checkbox clicked.
i have noticed that asp.net fully support js .
<script type="text/javascript">
$(document).ready(function () {
$('#chkhtml').change(function () {
$('#Text1').prop("disabled", !$(this).is(':checked'));
document.getElementById('#Text1').innerHTML = 'newtext';
document.getElementById('#<%=rollLbl.ClientID %>').innerHTML = 'your text goes here';
document.getElementById('#testlbl').innerHTML = 'newtext';
});
});
</script>
However it only enable or disable text box but don't change text of any label or text box.
i have already tried .value .content etc but none of these work plzzz plzz help me .
You have mixed up jQuery and Javascript:
jQuery
<script type="text/javascript">
$(document).ready(function() {
$('#chkhtml').change(function() {
$('#Text1').prop("disabled", !$(this).is(':checked'));
$('#Text1').val('newtext');
$('#<%=rollLbl.ClientID %>').html('your text goes here');
$('#testlbl').html('newtext');
});
});
</script>
Please amend below changes in your code, if you want to keep original.
<script type="text/javascript">
$(document).ready(function() {
$('#chkhtml').change(function() {
$('#Text1').prop("disabled", !$(this).is(':checked'));
document.getElementById('Text1').value = 'newtext';
document.getElementById('<%=rollLbl.ClientID %>').innerHTML = 'your text goes here';
document.getElementById('testlbl').innerHTML = 'newtext';
});
});
</script>
You need to change
document.getElementById('#Text1')
to
document.getElementById('Text1')
And the rest of such calls too. getElementById
accepts an ID, not a selector.
you may try in jquery
$('#Text1').html('newtext');
$('#<%=rollLbl.ClientID %>').html('your text goes here');
or in plain javascript
document.getElementById('Text1').innerHTML = 'newtext';
document.getElementById('<%=rollLbl.ClientID %>').innerHTML = 'your text goes here';
you need to pass only the id of the element to getelementById()
. but jquery uses css query selector so #name
means it is an id and .name
means it is a class
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.