1

データベース テーブルからフォームのドロップダウン ボックスに直接データをロードしています。特定の値がこのボックスに設定されているかどうか、ページの読み込みを確認しようとしています。デフォルトで無効になっていて非表示になっている別のドロップダウン ボックスを有効にしたい場合。

フォームの作成 (joomla) に Chronoforms v5 を使用しており、最初のドロップダウン ボックスで特定の値が選択された場合は 2 番目のドロップダウン ボックスを有効にして表示するイベントを設定し、最初のドロップダウン ボックスで値が選択されていない場合は逆に、または、必要な値とは異なる場合、2 番目のドロップダウン ボックスを無効にして非表示にします。ただし、これらのイベントは、ユーザーが最初のドロップダウン ボックスの値を積極的に変更した後にのみ発生します。ページの読み込み時にもイベントが発生する必要があります。

クロノフォームのjavascriptは

function chronoforms_fields_events(){

    $(':input[name="custom"]').on('change', function(){
        if($(this).val() == 'United_States'){
            $(':input[name="state"]').prop('disabled', false);
        }
    });

    $(':input[name="custom"]').on('change', function(){
        if($(this).val() == 'United_States'){

            if($(':input[name="state"]').closest('.gcore-subinput-container').length > 0){
                $(':input[name="state"]').closest('.gcore-subinput-container').show();
                }else if($(':input[name="state"]').closest('.gcore-form-row').length > 0){
                $(':input[name="state"]').closest('.gcore-form-row').show();
            }

        }
    });

    $(':input[name="custom"]').on('change', function(){
        if($(this).val() != 'United_States'){

            if($(':input[name="state"]').closest('.gcore-subinput-container').length > 0){
                $(':input[name="state"]').closest('.gcore-subinput-container').hide();
                }else if($(':input[name="state"]').closest('.gcore-form-row').length > 0){
                $(':input[name="state"]').closest('.gcore-form-row').hide();
            }

        }
    });

    $(':input[name="custom"]').on('change', function(){
        if($(this).val() != 'United_States'){
            $(':input[name="state"]').prop('disabled', true);
        }
    });

    $(':input[name="custom"]').on('click', function(){
        if($(this).prop('checked')){
            $(':input[name="state"]').prop('disabled', false);
        }
    });
}
chronoforms_fields_events();

そして、私は現在、HTML(Render form)の前にこのjavascriptを追加していますが、機能しません

 function validatecountry(){
 if ($("#custom").prop("selectedIndex", 'United_States')){
          $(':input[name="state"]').prop('disabled', false);
    if($(':input[name="state"]').closest('.gcore-subinput-container').length > 0){
                     $(':input[name="state"]').closest('.gcore-subinput-container').show();
                }else if($(':input[name="state"]').closest('.gcore-form-row').length > 0){
                $(':input[name="state"]').closest('.gcore-form-row').show();
            }

 }
 }
 validatecountry();

どんな助けでも大歓迎です

4

1 に答える 1