wolfgang1983 wolfgang1983 - 1 year ago 50
Javascript Question

Preview tab not showing when press editor buttons

When I type in my textarea once has dected more than 4 characters it enables the preview tab.

If I click on my editor buttons example the button-bold it shows text like

**strong text**
but even though there is more than 4 characters preview tab does not enabled.

Currently It only enabled when keyup

Question: How can I make sure if I click on a editor button it will
dected how many characters and if greater than 4 will enable tab.

CodePen Example Demo


$("#textarea_message").on('keyup', function(e){
if ($(this).val().length >= "4") {

if ($(this).val().length < "4") {


<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<form id="form-ask">

<div class="form-group">
<button type="button" id="button-bold" class="btn btn-default" title="Bold"><i class="fa fa-bold" aria-hidden="true"></i></button>
<button type="button" id="button-italic" class="btn btn-default" title="Italic"><i class="fa fa-italic" aria-hidden="true"></i></button>
<button type="button" id="button-quote" class="btn btn-default" title="Quote"><i class="fa fa-quote-left" aria-hidden="true"></i></button>
<button type="button" id="button-code" class="btn btn-default" title="Code"><i class="fa fa-quote-left" aria-hidden="true"></i></button>
<button type="button" id="button-insert-image" data-toggle="modal" data-target="#insert-image" class="btn btn-default" title="Insert Image URL"><i class="fa fa-code" aria-hidden="true"></i>
<button type="button" id="button-upload" class="btn btn-default" title="Add Attachment: This can be image or file "><i class="fa fa-file" aria-hidden="true"></i>
Attach File</button>

<div class="panel ask panel-default">
<div class="panel-heading">
<ul class="nav nav-tabs">
<li class="active"><a data-target="#ask" id="tab-ask" data-toggle="tab"><i class="fa fa-code" aria-hidden="true"></i> Ask Question</a></li>
<li><a data-target="#preview" id="tab-preview" data-toggle="tab"><i class="fa fa-eye" aria-hidden="true"></i> Preview</a></li>
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane fade in active" id="ask">
<div class="form-group">
<textarea id="textarea_message" class="form-control"></textarea>
<div class="tab-pane fade" id="preview">
<div class="preview-message"></div>
<p class="text-muted">Preview Button will be enabled once your question has reached
4 character or more.</p>


Answer Source

One solution would be to add a 'trigger' for the keyup event on your buttons

$('#button-bold').on('click', function(e) {
    markdown_syntax(this.id, "**", "**", 'strong text');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download