仅基于特定选择选项加载div控制器

时间:2017-04-28 14:35:09

标签: javascript html codeigniter

嗨,我有一个改变功能,可以在一个模态中加载一个div内容的控制器,如下图所示。

The Working Controller with div inside the modal

我的问题是每当我更改任何选择选项时它都会加载,我想要的是加载控制器,如果只选择了每月选项。

我的HTML选择选项是这样的:

<div class="form-group">
  <label for="registrationmodeofpayment" class="col-sm-4 control-label">Mode of Payment: </label>
    <div class="col-sm-8">

      <select class="form-control" name="registrationmodeofpayment" id="registrationmodeofpayment">
        <option value="">Select Mode of Payment</option>
        <option value="Annual">Annual (Full)</option>
        <option value="Monthly">Monthly</option>
      </select>

    </div>
</div>

// The div that have the id of modeofpayment.
<div class="col-md-12" id="modeofpayment"></div>

使用Javascript:

$("#registrationmodeofpayment").unbind('change').bind('change', function() {
    // Loads the controller
    $("#modeofpayment").load('registration/assessModeofPayment');
});

控制器:

public function assessModeofPayment()  
{   

      $div3 = '</table>
      <table class="table table-bordered">
        <tr>
          <th>Monthly Tuition Fee:</th>
          <td width="210px">*Amount*</td>
        </tr>
      </table>
      ';

    echo $div3;

}

1 个答案:

答案 0 :(得分:0)

好吧,我们已经得到了IF:

$("#registrationmodeofpayment").unbind('change').bind('change', function() {
    if($(this).val() == 'Monthly') {
        // Loads the controller
        $("#modeofpayment").load('registration/assessModeofPayment');
    }
});

希望我能帮助一点。