具有重力形式的动态复选框 select
Checkbox dynamic select with Gravity Forms
我有一个复选框,我想说这个复选框:如果(例如)“Einzelberatung BU”被 selected 并且你想 select 另一个带有术语“Einzelberatung ...”的字段那么字段“Komplettes Finanzkonzept”应该自动 selected 并且其他两个字段应该 deselected.
如您所见,我绝对是 javascript 的新手。所以希望有人可以帮助我解决我在下面粘贴的代码并告诉我我做错了什么。
感谢您的宝贵时间,
里昂
jQuery('#input_167_1 input[type="checkbox"]').on('click', function() {
var $bu = jQuery('#choice_2_9_1');
var $pkv = jQuery('#choice_2_9_2');
var $etf = jQuery('#choice_2_9_3');
var $fiko = jQuery('#choice_2_9_4');
// Check Green if Rea & Blue are checked.
if ($bu.is(':checked') && $etf.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
} else if ($bu.is(':checked') && $pkv.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
} else if ($pkv.is(':checked') && $etf.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
}
// Prevent Red & Blue from being checked if Green is checked.
else if ($fiko.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="gfield_checkbox" id="input_2_9">
<li class="gchoice_2_9_1">
<input name="input_9.1" type="checkbox" value="Einzelberatung BU" id="choice_2_9_1">
<label for="choice_2_9_1" id="label_2_9_1">Einzelberatung BU</label>
</li>
<li class="gchoice_2_9_2">
<input name="input_9.2" type="checkbox" value="Einzelberatung PKV" id="choice_2_9_2">
<label for="choice_2_9_2" id="label_2_9_2">Einzelberatung PKV</label>
</li>
<li class="gchoice_2_9_3">
<input name="input_9.3" type="checkbox" value="Einzelberatung ETF Rente" id="choice_2_9_3">
<label for="choice_2_9_3" id="label_2_9_3">Einzelberatung ETF Rente</label>
</li>
<li class="gchoice_2_9_4">
<input name="input_9.4" type="checkbox" value="investmentplanung" id="choice_2_9_4">
<label for="choice_2_9_4" id="label_2_9_4">investmentplanung</label>
</li>
<li class="gchoice_2_9_5">
<input name="input_9.5" type="checkbox" value="Komplettes Finanzkonzept" id="choice_2_9_5">
<label for="choice_2_9_5" id="label_2_9_5">Komplettes Finanzkonzept</label>
</li>
<li class="gchoice_2_9_6">
<input name="input_9.6" type="checkbox" value="Anderese Anliegen" id="choice_2_9_6">
<label for="choice_2_9_6" id="label_2_9_6">Anderese Anliegen</label>
</li>
</ul>
代码如下。我删除了 #input_167_1
并将 click
更改为 change
。
jQuery('input[type="checkbox"]').on('change', function() {
var $bu = jQuery('#choice_2_9_1');
var $pkv = jQuery('#choice_2_9_2');
var $etf = jQuery('#choice_2_9_3');
var $fiko = jQuery('#choice_2_9_4');
// Check Green if Rea & Blue are checked.
if ($bu.is(':checked') && $etf.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
} else if ($bu.is(':checked') && $pkv.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
} else if ($pkv.is(':checked') && $etf.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
}
// Prevent Red & Blue from being checked if Green is checked.
else if ($fiko.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="gfield_checkbox" id="input_2_9">
<li class="gchoice_2_9_1">
<input name="input_9.1" type="checkbox" value="Einzelberatung BU" id="choice_2_9_1">
<label for="choice_2_9_1" id="label_2_9_1">Einzelberatung BU</label>
</li><li class="gchoice_2_9_2">
<input name="input_9.2" type="checkbox" value="Einzelberatung PKV" id="choice_2_9_2">
<label for="choice_2_9_2" id="label_2_9_2">Einzelberatung PKV</label>
</li><li class="gchoice_2_9_3">
<input name="input_9.3" type="checkbox" value="Einzelberatung ETF Rente" id="choice_2_9_3">
<label for="choice_2_9_3" id="label_2_9_3">Einzelberatung ETF Rente</label>
</li><li class="gchoice_2_9_4">
<input name="input_9.4" type="checkbox" value="investmentplanung" id="choice_2_9_4">
<label for="choice_2_9_4" id="label_2_9_4">investmentplanung</label>
</li><li class="gchoice_2_9_5">
<input name="input_9.5" type="checkbox" value="Komplettes Finanzkonzept" id="choice_2_9_5">
<label for="choice_2_9_5" id="label_2_9_5">Komplettes Finanzkonzept</label>
</li><li class="gchoice_2_9_6">
<input name="input_9.6" type="checkbox" value="Anderese Anliegen" id="choice_2_9_6">
<label for="choice_2_9_6" id="label_2_9_6">Anderese Anliegen</label>
</li>
</ul>
我有一个复选框,我想说这个复选框:如果(例如)“Einzelberatung BU”被 selected 并且你想 select 另一个带有术语“Einzelberatung ...”的字段那么字段“Komplettes Finanzkonzept”应该自动 selected 并且其他两个字段应该 deselected.
如您所见,我绝对是 javascript 的新手。所以希望有人可以帮助我解决我在下面粘贴的代码并告诉我我做错了什么。
感谢您的宝贵时间, 里昂
jQuery('#input_167_1 input[type="checkbox"]').on('click', function() {
var $bu = jQuery('#choice_2_9_1');
var $pkv = jQuery('#choice_2_9_2');
var $etf = jQuery('#choice_2_9_3');
var $fiko = jQuery('#choice_2_9_4');
// Check Green if Rea & Blue are checked.
if ($bu.is(':checked') && $etf.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
} else if ($bu.is(':checked') && $pkv.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
} else if ($pkv.is(':checked') && $etf.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
}
// Prevent Red & Blue from being checked if Green is checked.
else if ($fiko.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="gfield_checkbox" id="input_2_9">
<li class="gchoice_2_9_1">
<input name="input_9.1" type="checkbox" value="Einzelberatung BU" id="choice_2_9_1">
<label for="choice_2_9_1" id="label_2_9_1">Einzelberatung BU</label>
</li>
<li class="gchoice_2_9_2">
<input name="input_9.2" type="checkbox" value="Einzelberatung PKV" id="choice_2_9_2">
<label for="choice_2_9_2" id="label_2_9_2">Einzelberatung PKV</label>
</li>
<li class="gchoice_2_9_3">
<input name="input_9.3" type="checkbox" value="Einzelberatung ETF Rente" id="choice_2_9_3">
<label for="choice_2_9_3" id="label_2_9_3">Einzelberatung ETF Rente</label>
</li>
<li class="gchoice_2_9_4">
<input name="input_9.4" type="checkbox" value="investmentplanung" id="choice_2_9_4">
<label for="choice_2_9_4" id="label_2_9_4">investmentplanung</label>
</li>
<li class="gchoice_2_9_5">
<input name="input_9.5" type="checkbox" value="Komplettes Finanzkonzept" id="choice_2_9_5">
<label for="choice_2_9_5" id="label_2_9_5">Komplettes Finanzkonzept</label>
</li>
<li class="gchoice_2_9_6">
<input name="input_9.6" type="checkbox" value="Anderese Anliegen" id="choice_2_9_6">
<label for="choice_2_9_6" id="label_2_9_6">Anderese Anliegen</label>
</li>
</ul>
代码如下。我删除了 #input_167_1
并将 click
更改为 change
。
jQuery('input[type="checkbox"]').on('change', function() {
var $bu = jQuery('#choice_2_9_1');
var $pkv = jQuery('#choice_2_9_2');
var $etf = jQuery('#choice_2_9_3');
var $fiko = jQuery('#choice_2_9_4');
// Check Green if Rea & Blue are checked.
if ($bu.is(':checked') && $etf.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
} else if ($bu.is(':checked') && $pkv.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
} else if ($pkv.is(':checked') && $etf.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
$fiko.prop('checked', true);
}
// Prevent Red & Blue from being checked if Green is checked.
else if ($fiko.is(':checked')) {
$bu.prop('checked', false);
$pkv.prop('checked', false);
$etf.prop('checked', false);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="gfield_checkbox" id="input_2_9">
<li class="gchoice_2_9_1">
<input name="input_9.1" type="checkbox" value="Einzelberatung BU" id="choice_2_9_1">
<label for="choice_2_9_1" id="label_2_9_1">Einzelberatung BU</label>
</li><li class="gchoice_2_9_2">
<input name="input_9.2" type="checkbox" value="Einzelberatung PKV" id="choice_2_9_2">
<label for="choice_2_9_2" id="label_2_9_2">Einzelberatung PKV</label>
</li><li class="gchoice_2_9_3">
<input name="input_9.3" type="checkbox" value="Einzelberatung ETF Rente" id="choice_2_9_3">
<label for="choice_2_9_3" id="label_2_9_3">Einzelberatung ETF Rente</label>
</li><li class="gchoice_2_9_4">
<input name="input_9.4" type="checkbox" value="investmentplanung" id="choice_2_9_4">
<label for="choice_2_9_4" id="label_2_9_4">investmentplanung</label>
</li><li class="gchoice_2_9_5">
<input name="input_9.5" type="checkbox" value="Komplettes Finanzkonzept" id="choice_2_9_5">
<label for="choice_2_9_5" id="label_2_9_5">Komplettes Finanzkonzept</label>
</li><li class="gchoice_2_9_6">
<input name="input_9.6" type="checkbox" value="Anderese Anliegen" id="choice_2_9_6">
<label for="choice_2_9_6" id="label_2_9_6">Anderese Anliegen</label>
</li>
</ul>