Yii2 - Show and Hide Div on Button Click is having issue

button click show and hide div jquery
php show hide div onclick
how to display a div only when a button is clicked
wordpress show hide div on click
onclick show div hide all others
css show hide div on click without javascript
change display on button click
a href onclick show div

I am trying to hide and show a div on button click. By default, I hide the div. When I click the button, it works initially. But I observed that after few seconds, the div hides or shows on its own without button click.

Button

    <div class="col-xs-12 col-sm-12 left-padding">
        <?= Html::a('<i class="fa fa-search-plus"></i>'.Yii::t('app', ' Display Advanced Search'), [''], ['class' => 'btn btn-block btn-warning', 'onclick' => "advancedSearch()"]) ?>
    </div>

Div to Hide or Show

    <div id="toggleSearch" class="col-xs-12" style="display:none">
    <div class="box"> 
        <div class="box-body table-responsive">
            <div class="col-xs-12">
                <h4><strong><u>Advanced Search</u></strong></h4>
            </div>
   <?php $form = ActiveForm::begin([
       'enableAjaxValidation' => false,
   'method' => 'get']); ?>
<div class="col-xs-12 col-lg-12 no-padding"> 
    <div class="col-xs-12 col-sm-6 col-lg-6">
          <?= $form->field($searchModel, 'zonal_office_id')->widget(Select2::classname(), [
                'data' => ArrayHelper::map(app\models\ZonalOffice::find()->all(),'id','zonal_office_name'),
                'language' => 'en',
                'options' => ['placeholder' => 'Select Zonal Office ...'],

             //   'disabled'=>'true',
                'pluginOptions' => [
                    'allowClear' => true
                ],
            ]); ?>        
    </div>
    <div class="col-xs-12 col-sm-6 col-lg-6">
  	<?= $form->field($searchModel, 'state_name')->textInput(['maxlength' => 100, 'placeholder' => $searchModel->getAttributeLabel('state_name')]) ?>
    </div>   
</div>
<div class="col-xs-12 col-lg-12"> 
    <div class="form-group">
        <?= Html::submitButton('Click to Search', ['class' => 'btn btn-success']) ?>
    </div>
</div>

    <?php ActiveForm::end(); ?>  
</div>
</div>
</div>

javascript - Yii2, I am trying to hide and show a div on button click. By default, I hide the div. When I click the button, it works initially. But I observed that after few  Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

The problem here is that the event handler is not bound on the same context as the listener is looking at for it to find.

If you bind the handler directly on the html element (as in the example you provided), the handler is expected to be available on the window object.

There's a quick fix for this; if you bind the handler explicitly to the window object. It's not the cleanest way, but it solves this problem.

<script>
window.advancedSearch = function advancedSearch() {
  var x = document.getElementById("toggleSearch");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
</script>

A cleaner approach would be to provide an id property to the item and bind the handler on the DOM element once the page completed loading.

eg:

<script>
function advancedSearch() {
  var x = document.getElementById("toggleSearch");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}

document.addEventListener("DOMContentLoaded", function(event) {
  document.getElementById("MyButton").onclick = advancedSearch;
});
</script>

Edit: I put together an example on js fiddle that supports the behaviour: https://jsfiddle.net/rv20yq7k/

Show/hide a div in Yii radio button click - css - html, Iam trying to show/hide a div based on the radio button click in Yii form. But the onclick event is not working for me. the main JS is tested to work with all primary browser. but i wrote in live the html that have to be generated. hope it works all! Empty help-block DIV below but it comes up pretty high on Google and I feel a solid response for Yii 2's current state is missing. The above code snippets

you need to use this function event.preventDefault() to prevent the link from working as it should, to avoid reloading the page because your button is a link and is reloading the page every time you click, and for that your "div" will hide again

function advancedSearch() {
    event.preventDefault(); // to prevent reload the page
    var x = document.getElementById("toggleSearch");
    if (x.style.display === "none") {
        x.style.display = "block";
    } else {
        x.style.display = "none";
    }
}

Show hide div layer onclick of buttons, Showing & hiding div layers on button clicks. Div Layer show hide We can control a layer by connecting it to buttons. We can display or hide the layer by clicking  Please note, that the GitHub Issue Tracker is for bug reports and feature requests only. We are happy to help you on the support forum , on IRC (#yii on freenode), or Gitter . Please use one of the above mentioned resources to discuss the problem.

How To Hide And Show A Div From A Button On Cmenu Yii , I would like to show/hide a Div in my page, whenever I click on a button ON MY CMenu. I tried so many solutions and nothing works for me. I have 3 divs: default or one 2 3 I wanna show default or one div on load meaning it will always be visible and divs 2 and 3 hidden. Now when you click on 2 or 3 it will show its content and hide

jcontextmenu | Extensions, This allows injecting and removing triggers without having to re-initialize or update contextMenu. <div class="context-menu-one box menu-1"> <strong>​right click using right button click me</h5> </div> <button value="this can also trigger the <menu id="html5menu" type="context" style="display:none"  When ajax validation is enabled and I click submit button in Chrome - two records appears in DB. This occures in Chrome only. On submit I see 1 request to the server in FF and 2 in Chrome. This issue reproducing when you type in field and then QUICKLY click Submit button. When you do it slowly it works correctly (depends on server speed).

Show Hide DIV Based on Radio Buttons Selection Using jQuery, Here are some more FAQ related to this topic: Show and hide DIV elements based on click of checkboxes in jQuery · Show and hide DIV elements based on​  CHtml is a static class that provides a collection of helper methods for creating HTML views. Nearly all of the methods in this class allow setting additional html attributes for the html tags they generate. You can specify for example. 'class', 'style' or 'id' for an html element.

Comments
  • is it showing and hiding by itself or if you click anywhere other than the anchor ?
  • If I click on it it shows, but in just 1 or 2 seconds it hides by itself
  • Please can you explan function(event) and ("MyButton")
  • Sorry for my bad English