如果我选中一个复选框,我将停用另一个
情况是这样的:正如您在下面的可视示例中看到的那样.我有四个按钮的单选按钮-我需要创建一个事件,当我选择Compo的选项"no"时,我会自动禁用字段中的两个选择.
如果选择了"是",则其他两个选项必须保持活动状态.我的问题是,这四枚邮票是"单选按钮",而不是一个复选框.
可视化示例:
⬜是⬜否
⬜拥有捐赠者的⬜
我有这个片断:
选择 | 换行 | 行号
- Code 1
- Base PHP code I'm using.
- <!-- IVF fertilization -->
- <div class='col-sm-4'>
- <?=_('IVF fertilization')?>
- <div>
- <input type="radio" id="yesFe" name="niptData_ivfFertilization" value='1'
- <?=($_SESSION['REQUEST']['niptData_ivfFertilization-required0allow'] == '1' OR $registration->test->data->ivfFertilization == '1') ? 'checked' : ''?>
- >
- <label for="yesFe" class='smallLabel'><?=_('Yes')?></label>
- </div>
- <div>
- <input type="radio" id="noFe" name="niptData_ivfFertilization" value='0'
- <?=($_SESSION['REQUEST']['niptData_ivfFertilization-required0allow'] == '0' OR $registration->test->data->ivfFertilization == '0') ? 'checked' : ''?>
- >
- <label for="noFe" class='smallLabel'><?=_('No')?></label>
- </div>
- </div>
- <!-- if IVF ovum -->
- <div class='col-sm-4'>
- <?=_('If IVF ovum')?>
- <div>
- <input type="radio" id="ownOv" name="niptData_ovum" value='1' data-validation=""
- <?=($_SESSION['OPTIONAL']['niptData_ovum'] == '1' OR $registration->test->data->ovum == '1') ? 'checked' : ''?>
- >
- <label for="ownOv" class='smallLabel'><?=_('Own')?></label>
- </div>
- <div>
- <input type="radio" id="fromADonor" name="niptData_ovum" value='2' data-validation=""
- <?=($_SESSION['OPTIONAL']['niptData_ovum'] == '2' OR $registration->test->data->ovum == '2') ? 'checked' : ''?>
- >
- <label for="fromADonor" class='smallLabel'><?=_('From a donor')?></label>
- </div>
- <br>
- </div>
- CODE 2
- Script that working to solve the problem.
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
- <script>
- $(document).ready(function () {
- $('#new_user_form *').filter(':radio').change(function() {
- if(this.id=='noFe' && this.value=='0' && $(this).is(':checked')) {
- $('#new_user_form *').filter(':radio').each(function(){
- if(this.id=='noFe' && this.value=='0') {
- } else {
- $(this).attr("checked",false);
- }
- });
- }
- if((this.id=='ownOv' || this.id=='fromADonor' && this.value=='0') {
- var checkedId = this.id;
- var checkedOrNot = $(this).is(':checked');
- $('#new_user_form *').filter(':radio').each(function(){
- if(this.id==checkedId && (this.value=='1' || this.value=='2')) {
- if(checkedOrNot) {
- $(this).attr("disabled",true);
- } else {
- $(this).attr("disabled",false);
- }
- }
- });
- </script>
- CODE 3
- HTML code that was asked of me.
- <div class="col-sm-4">
- Pregnancy<span class="required">*</span>
- <div class="has-error">
- <input type="radio" id="yesFe" name="niptData_ivfFertilization-required0allow" value="1" data-validation="required" class="error" style="border-color: rgb(185, 74, 72);">
- <label for="yesFe" class="smallLabel">Yes</label>
- <span class="help-block form-error">Required field</span></div>
- <div class="has-success">
- <input type="radio" id="noFe" name="niptData_ivfFertilization-required0allow" value="0" data-validation="required" class="valid" style="">
- <label for="noFe" class="smallLabel">No</label>
- </div>
- </div>
- <div class="col-sm-4">
- if FIVET, ovum<span class="optional"></span>
- <div>
- <input type="radio" id="ownOv" name="niptData_ovum" value="1" data-validation="">
- <label for="ownOv" class="smallLabel">Own</label>
- </div>
- <div>
- <input type="radio" id="fromADonor" name="niptData_ovum" value="2" data-validation="">
- <label for="fromADonor" class="smallLabel">
- As a donor</label>
- </div>
- <br>
- </div>