我有一个表单,其中,我想选择组织名称,然后自动需要在另一个文本框中显示该组织名称的hq no,两者是否在同一个表中。
<div class="form-group"><label for="orgName">Org Name</label>
<select class="form-control required" id="orgName"name="orgName"> <option value="0">
Select Orgnization</option>
<?php if(!empty($orgNames)){ foreach ($orgNames as $pl){ ?><option value="<?php echo $pl->customerId ?>"><?php echo $pl->orgName ?></option><?php}?> </select>
</div></div>
<div class="form-group">
<label for="hqNo">HQ No.</label>
<input type="text" class="form- control required" id="hqNo" name="hqNo" maxlength="128">
</div>
答案 0 :(得分:0)
假设该组织的选项值为hqNo:
<div class="form-group">
<label for="orgName">Org Name</label>
<select class="form-control required" id="orgName" name="orgName" onchange="onOrganizationChange()">
<option value="0">Select Orgnization</option>
<?php if(!empty($orgNames)) { foreach ($orgNames as $pl){ ?>
<option value="<?php echo $pl->customerId ?>"><?php echo $pl->orgName; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label for="hqNo">HQ No.</label>
<input type="text" class="form-control required" id="hqNo" name="hqNo" maxlength="128">
</div>
<script>
function onOrganizationChange() {
var orgVal = document.getElementById("orgName").value;
document.getElementById('hqNo').value = orgVal;
}
</script>