0

チェックボックスのクリック イベントに問題があります。ユーザーは、入力値のグローバル変数を作成する 5 つの入力を入力します。次に、ユーザーはフォームの残りの部分に入力し、確認チェックボックスをクリックして規則/規制に同意します。このチェックボックスは、事前に定義されたテキストと混合された 5 つの変数を非表示のテキストエリアに入力する必要があります。

ほとんどの場合は機能しているようですが、空白のエントリがいくつかあります。したがって、チェックボックス トリガー イベントが正しく発生しません。広範なブラウザ テストを実施しましたが、原因を特定することはできません。

Facebookのコンテスト/懸賞用のShortstack App Platformでカスタムコードを使用しています。

イベントをトリガーするために次の両方を試しましたが、どちらも問題を解決しません。

$('#promotion_agree').change(function() {

$('#promotion_agree').on("click", function(event) { 

私のコードは以下です。どんな助けでも大歓迎です。

<script type="text/javascript">

jQuery(document).ready(function($) {

//Fade out the Agree to Rules/Regulations checkbox

$('#promotion_agree_block').fadeOut();

//Input Field 1
$('#promotion_custom_field_2').bind("keyup change", function() {
  fieldone = $(this).val();
  $('#promotion_custom_field_5').val(fieldone);
});

//Input Field 2
$('#promotion_custom_field_3').bind("keyup change", function() {
  fieldtwo = $(this).val();
  $('#promotion_custom_field_7').val(fieldtwo);
});

//Input Field 3
$('#promotion_custom_field_4').bind("keyup change", function() {
  fieldthree = $(this).val();
  $('#promotion_custom_field_8').val(fieldthree);
});

//Input Field 4
 $('#promotion_custom_field_17').bind("keyup change", function() {
   fieldfour = $(this).val();
   $('#promotion_custom_field_9').val(fieldfour);
});

//Input Field 5
$('#promotion_custom_field_18').bind("keyup change", function() {
  fieldfive = $(this).val();
  $('#promotion_custom_field_37').val(fieldfive);
  $('#promotion_agree_block').fadeIn();  
});



////Post the global variables to the hidden textarea along with the included text

$('#promotion_agree').on("click", function(event) { 

//The following code is placed in the textarea field that is hidden

$('#promotion_image_description').html('' + fieldone + ' walked through The Fair, after     enjoying the Superdogs show where he saw lots of ' + fieldtwo + ', ' + fieldthree + ' dogs. They leapt through hoops and over jumps and ' + fieldfour + ' with their trainers. He thought about how great it would be if his dog ' + fieldfive + ' became a Superdog! Maybe one day...\r\n\r\n Submitted Words: ' + fieldone + ', ' + fieldtwo + ', ' + fieldthree + ', ' + fieldfour + ', ' + fieldfive + ''.replace(/\r\n/g, '\n').split('\n')); 


  });
});
</script>

以下の元の投稿に編集...

HTML コードは次のようになります。

入力の 1 つが次のようになります。

<div class="field_block custom_field_2_field_block text_field_type_block center-input" id="promotion_custom_field_2_block">
<label for="promotion_custom_field_2"><span class="main_field_label">Field One</span><span class="required">*</span></label>
<input class="small" id="promotion_custom_field_2" name="promotion[custom_field_2]" type="text">
</div>

これは、イベントをトリガーしてテキストエリアに投稿するチェックボックスです。

<div class="field_block agree_field_block black-text" id="promotion_agree_block" style="display: block;">
<label for="promotion_agree"><input id="promotion_agree" name="promotion[agree]" type="checkbox" value="1"> <span class="main_field_label">I have read and agree to the rules &amp; regulations</span><span class="required">*</span></label>
</div>

上記のチェックボックスをオンにすると、テキスト領域は次のようになります。

<div class="field_block image_description_field_block" id="promotion_image_description_block">
<label for="promotion_image_description"><span class="main_field_label">MadLib Story</span></label>
<textarea class="medium" id="promotion_image_description" name="promotion[image_description]">test1 walked through The Fair, after enjoying the Superdogs show where he saw lots of test2, test3 dogs. They leapt through hoops and over jumps and test4 with their trainers. He thought about how great it would be if his dog test5 became a Superdog! Maybe one day...

提出単語: test1, test2, test3, test4, test5

2 番目の編集 ここでは、各要素が入力されたときに説明フィールドにデータを入力するための Javascript コードの編集を示します。何らかの理由で、送信時にフォームに説明テキストが入力されないため、これが機能する可能性があると考えました。

<script type="text/javascript">

jQuery(document).ready(function($) {


$('#promotion_custom_field_2').bind("keyup change", function() {
//Create Global Variable for Text entered
  fieldone = $(this).val();

  //Add Global Variable to Hidden Field
  $('#promotion_custom_field_5').val(fieldone);

  //Update Description Field if Changed
  $('#promotion_image_description').html('' + fieldone + ' walked through The Fair, after enjoying the Superdogs show where he saw lots of '
                                         + fieldtwo + ', ' + fieldthree + ' dogs. They leapt through hoops and over jumps and ' 
                                         + fieldfour + ' with their trainers. He thought about how great it would be if his dog ' 
                                         + fieldfive + ' became a Superdog! Maybe one day...\r\n\r\n Submitted Words: ' + fieldone + ', ' + fieldtwo + ', ' + fieldthree + ', ' + fieldfour + ', ' + fieldfive + ''.replace(/\r\n/g, '\n').split('\n'));

});



$('#promotion_custom_field_3').bind("keyup change", function() {
//Create Global Variable for Text entered
  fieldtwo = $(this).val();

  //Add Global Variable to Hidden Field
  $('#promotion_custom_field_7').val(fieldtwo);

  //Update Description Field if Changed
  $('#promotion_image_description').html('' + fieldone + ' walked through The Fair, after enjoying the Superdogs show where he saw lots of '
                                         + fieldtwo + ', ' + fieldthree + ' dogs. They leapt through hoops and over jumps and ' 
                                         + fieldfour + ' with their trainers. He thought about how great it would be if his dog ' 
                                         + fieldfive + ' became a Superdog! Maybe one day...\r\n\r\n Submitted Words: ' + fieldone + ', ' + fieldtwo + ', ' + fieldthree + ', ' + fieldfour + ', ' + fieldfive + ''.replace(/\r\n/g, '\n').split('\n'));


});

$('#promotion_custom_field_4').bind("keyup change", function() {
//Create Global Variable for Text entered
  fieldthree = $(this).val();

  //Add Global Variable to Hidden Field
  $('#promotion_custom_field_8').val(fieldthree);

  //Update Description Field if Changed
  $('#promotion_image_description').html('' + fieldone + ' walked through The Fair, after enjoying the Superdogs show where he saw lots of '
                                         + fieldtwo + ', ' + fieldthree + ' dogs. They leapt through hoops and over jumps and ' 
                                         + fieldfour + ' with their trainers. He thought about how great it would be if his dog ' 
                                         + fieldfive + ' became a Superdog! Maybe one day...\r\n\r\n Submitted Words: ' + fieldone + ', ' + fieldtwo + ', ' + fieldthree + ', ' + fieldfour + ', ' + fieldfive + ''.replace(/\r\n/g, '\n').split('\n'));

});

   $('#promotion_custom_field_17').bind("keyup change", function() {
   //Create Global Variable for Text entered
  fieldfour = $(this).val();

  //Add Global Variable to Hidden Field
  $('#promotion_custom_field_9').val(fieldfour);

  //Update Description Field if Changed
  $('#promotion_image_description').html('' + fieldone + ' walked through The Fair, after enjoying the Superdogs show where he saw lots of '
                                         + fieldtwo + ', ' + fieldthree + ' dogs. They leapt through hoops and over jumps and ' 
                                         + fieldfour + ' with their trainers. He thought about how great it would be if his dog ' 
                                         + fieldfive + ' became a Superdog! Maybe one day...\r\n\r\n Submitted Words: ' + fieldone + ', ' + fieldtwo + ', ' + fieldthree + ', ' + fieldfour + ', ' + fieldfive + ''.replace(/\r\n/g, '\n').split('\n')); 

});

   $('#promotion_custom_field_18').bind("keyup change", function() {
//Create Global Variable for Text entered
  fieldfive = $(this).val();

  //Add Global Variable to Hidden Field
  $('#promotion_custom_field_37').val(fieldfive);

  //Update Description Field if Changed
  $('#promotion_image_description').html('' + fieldone + ' walked through The Fair, after enjoying the Superdogs show where he saw lots of '
                                         + fieldtwo + ', ' + fieldthree + ' dogs. They leapt through hoops and over jumps and ' 
                                         + fieldfour + ' with their trainers. He thought about how great it would be if his dog ' 
                                         + fieldfive + ' became a Superdog! Maybe one day...\r\n\r\n Submitted Words: ' + fieldone + ', ' + fieldtwo + ', ' + fieldthree + ', ' + fieldfour + ', ' + fieldfive + ''.replace(/\r\n/g, '\n').split('\n')); 


 });


  });
  </script>
4

2 に答える 2