私はコーディングに新しいが、自分自身を助けようとしている。もし誰かが偉大なことを示唆することができます。自動選択値<select multiple multiple = "multiple">
私は下のフォームを作成しているプラグインを使用しています。私はブラウザ上の要素を調べることでこれをチェックしました。
<select multiple="multiple" name="attendee_information_fields[]" id="attendee_information_fields" class="event-manager-multiselect" data-no_results_text="No results match" attribute="" data-multiple_text="Select Some Options" style="display: none;">
<option value="full-name">Full name</option>
<option value="email-address">Email address</option>
<option value="phone">Phone</option>
<option value="location">Location</option>
<option value="gender">Gender</option>
<option value="age">Age</option>
<option value="terms-conditions">Terms & Conditions</option>
<option value="become-a-cfp-camper">Become a CFP Camper</option>
</select>
これは必須フィールドです。私が望むのは、値がterms-conditions
とbecome-a-cfp-camper
で自動的に選択されるオプション値です。このために、私は私のテーマのfunctions.php
ファイル内のコードの下に書いています:
if($_POST['attendee_information_fields']) { echo "
<script type='text/javascript'>
$('#attendee_information_fields').click(function() {
$('select#terms-conditions > option').attr('selected', 'selected');
$('select#become-a-cfp-camper > option').attr('selected', 'selected');
});
</script>";
}
何が起こるように思わないと私は無知です。どのように私はこれを達成することができますか?どうもありがとう。
あなたの答えに感謝。問題は、この関数をどこに貼り付けるのかです。私はこのフォームがプラグインによってどこから生成されているのかわからないので、これをfunctions.phpファイルにエコーしようとしています(元の投稿をチェックしてください)、何も起こりません。結果を達成するためにこのコードを貼り付けるべきですか?多くのありがとう –