ドロップダウンリストと可変量のオプション(チェックボックスとテキスト入力の形式)を備えたフォームがあります。
私が達成したいのは、ドロップダウン リストの値を変更し、Web サービスを呼び出し、その下にあるさまざまなオプションをロードすることです。大まかに言うと、jQuery の onchange イベントを使用し、Ajax にマークアップを div に読み込ませる必要があります。
しかし、どうすれば正確にそれを達成できますか?
Bootstrap 3 を使用しています。フォーム コードの一部を以下に示します。ただし、Javascript または Ajax 部分の作成方法がわかりません。
ドロップダウンリスト
<div class="form-group">
<label for="inputBranch" class="col-lg-2 control-label">Branch</label>
<div class="col-lg-10">
<select class="form-control" id="resBranch">
<?php
// print all branch name
// if is same as merchantID, mark as selected
foreach($branchesArray as $branch) {
if($branch['merchantID'] == $merchantID) {
echo "<option selected>" . $branch['name'] . "</option>";
} else {
echo "<option>" . $branch['name'] . "</option>";
}
}
?>
</select>
</div>
</div>
オプション
<div class="form-group">
<label for="" class="col-lg-2 control-label">Options</label>
<div class="col-lg-10">
<?php
foreach ($featuresArray as $feature) {
?>
<div class="checkbox">
<label>
<input type="checkbox" value="<?php echo $feature['customValue']; ?>">
<?php echo $feature['customValue']; ?>
</label>
</div>
<?php
} // end foreach
?>
</div>
</div>