0

ドロップダウンの結果に基づいてフィールドを表示/非表示にする必要がある基本的な Web フォームがあります。現在持っているものは次のとおりです。

 <% choose_me = "--Choose one--" %>
<script type="text/javascript"> 
var f_distributor;  

function show_hide_fields(type){
    if (show_hide_fields == "Retailer"){            
        f_distributor = new LiveValidation('i_distributor');
        f_distributor.add( Validate.Presence );         
        $('#distributor').show();
    }
    if (show_hide_fields == "Distributor"){
        f_distributor.destroy();            
        $('#distributor').hide();           
    }
    if (show_hide_fields == "Direct Purchase Retailer"){
        f_distributor.destroy();            
        $('#distributor').hide();
    }
    if (show_hide_fields == "Distributor Rep"){
        f_distributor.destroy();            
        $('#distributor').hide();
    }
    if (show_hide_fields == "Catalog/E-Commerce Company"){
        f_distributor.destroy();            
        $('#distributor').hide();
    }
    if (show_hide_fields == "Other"){
        f_distributor.destroy();            
        $('#distributor').hide();
    }
    if (show_hide_fields == "--Choose one--"){
        f_distributor.destroy();            
        $('#distributor').hide();
    }
}
$(document).ready(function(){

    f_distributor = new LiveValidation('i_distributor');
    var f_type = new LiveValidation('i_type');
    f_type.add( Validate.Exclusion, { within: ['<%= choose_me %>'], failureMessage: "You must choose from the list."} );
    var f_dealer_business_name = new LiveValidation('i_dealer_business_name');
    f_dealer_business_name.add( Validate.Presence );
    var f_dealer_address1 = new LiveValidation('i_dealer_address1');
    f_dealer_address1.add( Validate.Presence );
    var f_dealer_city = new LiveValidation('i_dealer_city');
    f_dealer_city.add( Validate.Presence );
    var f_dealer_state = new LiveValidation('i_dealer_state');
    f_dealer_state.add( Validate.Exclusion, { within: ['<%= choose_me %>'], failureMessage: "You must choose from the list."} );
    var f_dealer_zip = new LiveValidation('i_dealer_zip');
    f_dealer_zip.add( Validate.Presence );
    f_dealer_zip.add( Validate.Length, { minimum: 5 } )
    var f_phone = new LiveValidation('i_phone');
    f_phone.add( Validate.Presence );
    f_phone.add( Validate.Length, { minimum: 10 } )
    var f_user_name = new LiveValidation('i_user_name');
    f_user_name.add( Validate.Presence );
    f_user_name.add( Validate.Email )
    var f_password = new LiveValidation('i_password');
    f_password.add( Validate.Presence );
    f_password.add( Validate.Length, { minimum: 6 } );
    var f_terms_acceptance = new LiveValidation('i_terms_acceptance', { insertAfterWhatNode: 'terms_acceptance_error' });
    f_terms_acceptance.add ( Validate.Acceptance );
    show_hide_fields($("input[@name='i_account']:checked").val());
});

                <div class="field"><%= select_tag "i[type]", options_for_select([ choose_me, "Retailer", "Distributor", "Direct Purchase Retailer", "Distributor Rep", "Catalog/E-Commerce Company", "Other" ], choose_me), :onchange => "if(show_hide_fields.value =='Retailer'){$('#distributor').show()} else {$('#distributor').hide()}; return false" %></div>             

フォームはエラーをスローしていませんが、隠しフィールドも表示していません。フィールドを表示および非表示にするために id を使用しています。どんな助けでも大歓迎です。

4

0 に答える 0