I try to show/hide a tinymce with radobutton. Like yes/no. So there are two radio buttons. yes - will show the tiny mce and no will hide the tinymce.
I have this:
showing tiny mce:
<div class="form-group">
@Html.Label(Resources.Entity.Product.PdfMessage, new { @class = "text-bold control-label col-md-2" })
<div class="col-lg-6 col-md-8 col-sm-10 ">
@Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { @class = "form-control tiny-mce", data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name, id = "tinyMCE" } })
@Html.ValidationMessageFor(model => mailModel.PdfMessage)
@*@Html.TextArea("MailProductHandlers_message", mailModel.Message, new { @class = "form-control", @rows = 15 })*@
</div>
</div>
these are my radio buttons:
<div class="form-group">
@Html.Label(Resources.Entity.Product.GeneratePDF, new {@class = "text-bold control-label col-md-2" })
<div class="col-lg-6 col-md-8 col-sm-10 ">
@Html.Label(Resources.Entity.Product.GeneratePDFYes) @Html.RadioButtonFor(model => model.IsChecked, "Yes", new { @checked = true, id = "radioButton" })
@Html.Label(Resources.Entity.Product.GeneratePDFNo) @Html.RadioButtonFor(model => model.IsChecked, "No", new { @checked = true, id = "radioButton2" })
</div>
</div>
and this is my javascript:
<script>
$(document).ready(function () {
$("input[Id='radioButton']").click(function () {
if ($(this).is(':checked')) {
$('#tiny-mce').show();
}
else {
$('#tiny-mce').hide();
}
});
});
</script>
if I do this: $('#mceu_61').hide();
it hides the editor. but after I press on yes, it shows the editor. but if I then press No it doesnt hide anymore. And I have this:
@Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { @class = "form-control tiny-mce", @id = "mceu_61", data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name } })
Your missing an @symbol for the id attribute: Modify your script as well like this:
***EDIT some thing seems off about the radio buttons only one should be checked and they should have the same name **
you can use the # to denote and ID in Jquery by the way instead off looking it up by attribute
EDIT I changed a few things around, I don't think you need two individual ids I grouped them with a class, you should be able to check the on change event from that class instead of checking on both ids
@Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { @class = "form-control tiny-mce", @id = "tinyMCE", @data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name } })
@Html.RadioButtonFor(model => model.IsChecked, "Yes", new { @checked = true, @class = "pdfchecker" })
// only one should be checked
@Html.RadioButtonFor(model => model.IsChecked, "No", new { @checked = false, @class = "pdfchecker" })
<script>
// this is short hand for document ready
$(function () {
//# is to denote an ID, . is to denote a class in jQuery the change function is hit when a radio button is change check the name to make sure they are apart of the same grouping
$(".pdfchecker").change(function () {
if ($(this).is(':checked')) {
$('#tiny-mce').show();
}
else {
$('#tiny-mce').hide();
}
});
</script>
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.