to do this I have to refresh the page? if so then I have to keep all the user entered details. Any simple elegant solution please?
Asked
Active
Viewed 114 times
-1
-
Why the heck has this been down-voted? – agAus Nov 26 '14 at 00:49
2 Answers
1
Assuming you have a span that contains the asterisk, you can simply use JQuery to clear the text when the checkbox is cleared.
$("#idOfCheckbox").click(function() {
if(this.is(':checked') == true) {
$("#idOfAsterisk").text("");
}
});

user3334871
- 1,251
- 2
- 14
- 36
-
-
your code works perfect, but I still wonder how the page shows or not shows * without refreshing page? Ajax? – kneethan Nov 26 '14 at 06:22
-
@kneethan Hi, sorry about the wait, might be on different timezones. JQuery and javascript are dynamic languages, that `.click()` causes the function code to be executed whenever a user "clicks" that element. – user3334871 Nov 26 '14 at 16:22
-
Thanks for the explanation, if you got time could you pls check my other question where I didn't satisfy with given answers since those are not working 100%, http://stackoverflow.com/questions/26173655/dropdownlist-inside-div-to-show-onmouseover-tooltip – kneethan Nov 27 '14 at 03:00
0
Basically you want to toggle a CSS class on that control. So you could use the following for example:
<asp:Label ID="Label1" runat="server" Text="Label" ClientIDMode="Static" EnableViewState="True"></asp:Label>
<input type="checkbox" id="checkbox1" /> <br />
and then some CSS:
/* Required Field Asterix Suffix */
.form-field-required:after {
color: red;
content: " *";
font-weight: bold;
}
and then some JS to do the toggle:
$(document).ready(function() {
$('#checkbox1').click(function() {
if (!$(this).is(':checked')) {
$('#Label1').addClass('form-field-required');
else
$('#Label1').removeClass('form-field-required');
}
});
});
On PostBack because you are keeping the viewstate for Label1 you will still have the asterix or not as needed.

TheEdge
- 9,291
- 15
- 67
- 135