简体   繁体   中英

unable to display div even if condition is true, always displaying else part in php

I am trying to show div on tab click only if condition is true, but always i am getting else div which is displayed in else part even when if condition is true

 $('#err').removeClass('uk-active'); 
 $('#MA_st').addClass('uk-active');

i have tried above code on success ajax call and also tried the following on tab click

 $("#tab_list").on('click','li',function (){
      $('#err').removeClass('uk-active'); 
      $('#MA_st').addClass('uk-active');
 });

here is my php code to show div in view file

<?php 
  $state_val = "";
  if(isset($_GET['state_val'])){
    $state_val = $_GET['state_val'];
    print_r($state_val);
  }
  if($data['state'] == 'MA' || $state_val == 'MA'){?>
    <div id="MA_st">
      <li>
          <div class="uk-form-row">
              <label class="uk-form-label"><?php echo Yii::t("default","Number")?></label>
              <?php echo CHtml::textField('txt_number',
                  isset($data['number'])?$data['number']:""
                  ,array(
                      'class'=>'uk-form-width-large'
                  ))?>
          </div>

          <div class="uk-form-row">
              <label class="uk-form-label"><?php echo Yii::t("default","Name")?></label>
              <?php echo CHtml::textField('txt_name',
                  isset($data['name'])?$data['name']:""
                  //"ABC"
                  ,array(
                      'class'=>'uk-form-width-large',
                      'autocomplete'=>"off"
                  ))?>
          </div>
      </li>
  </div>
<?php }else{?>
    <div id="err">
    <p>Inforamtion is not avaialble</p>
</div>

In either case of "If" or "Else" the second div is not being rendered, JS needs both divs to be rendered properly, try something like

<?php
  $state_val = "";
  if(isset($_GET['state_val'])){
    $state_val = $_GET['state_val'];
    print_r($state_val);
  }
  if($data['state'] == 'MA' || $state_val == 'MA'){?>
<div id="MA_st" class="uk-active">
    <li>
        <div class="uk-form-row">
            <label class="uk-form-label"><?php echo Yii::t("default","Number")?></label>
            <?php echo CHtml::textField('txt_number',
            isset($data['number'])?$data['number']:""
            ,array(
            'class'=>'uk-form-width-large'
            ))?>
        </div>

        <div class="uk-form-row">
            <label class="uk-form-label"><?php echo Yii::t("default","Name")?></label>
            <?php echo CHtml::textField('txt_name',
            isset($data['name'])?$data['name']:""
            //"ABC"
            ,array(
            'class'=>'uk-form-width-large',
            'autocomplete'=>"off"
            ))?>
        </div>
    </li>
</div>
<div id="err">
    <p>Inforamtion is not avaialble</p>
    <?php }else{?>
    <div id="MA_st">
        <li>
            <div class="uk-form-row">
                <label class="uk-form-label"><?php echo Yii::t("default","Number")?></label>
                <?php echo CHtml::textField('txt_number',
                isset($data['number'])?$data['number']:""
                ,array(
                'class'=>'uk-form-width-large'
                ))?>
            </div>

            <div class="uk-form-row">
                <label class="uk-form-label"><?php echo Yii::t("default","Name")?></label>
                <?php echo CHtml::textField('txt_name',
                isset($data['name'])?$data['name']:""
                //"ABC"
                ,array(
                'class'=>'uk-form-width-large',
                'autocomplete'=>"off"
                ))?>
            </div>
        </li>
    </div>
    <div id="err" class="uk-active">
        <p>Inforamtion is not avaialble</p>
    </div>
    }?>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM