Solved

Conditional custom field for registration form

ikrama
Shopify Partner
7 0 0

Hello 

 

I am trying to add some extra input in the registration form conditionally, check my example code. 

 

It is not working properly. Can anyone help me to fix the issue? It is always adding a customer tag 

Distributors and also, the information is not correctly working. 
 
If we can apply it by the liquid condition it should work, but I am not sure, how I do that. I am not sure, how to apply the condition based on my selection value. 
 
Thank you

 

 

 

<select id="rd_customer_status">
                    <option>Select...</option>
                    <option value="Retailers">Retailers</option>
                    <option value="Distributors">Distributors</option>
                </select>
        
                <div id="showRetailers" class="myDiv">
                  <input type="hidden" name="customer[tags]" value="Retailers">
                  <label for="customer_store_address">Address</label>
                  <input type="text" id="customer_store_address" name="customer[note][Retailers Address]">
                </div>
        
                <div id="showDistributors" class="myDiv">
                  <input type="hidden" name="customer[tags]" value="Distributors">
                  <label for="d_customer_store_address">Address</label>
                  <input type="text" id="d_customer_store_address" name="customer[note][Distributors Address]">
                  <label for="customer_store_website">Website URL</label>
                  <input type="text" id="customer_store_website" name="customer[note][Website URL]">
                </div>

    

                <script>
                $(document).ready(function(){
                    $('#rd_customer_status').on('change', function(){
                    var demovalue = $(this).val(); 
                        $("div.myDiv").hide();
                        $("#show"+demovalue).show();
                    });
                });
                </script>

 

 

 

ikrama_0-1674232727614.png

ikrama_1-1674232770472.png

 

Accepted Solution (1)

gr_trading
Shopify Partner
1591 138 171

This is an accepted solution.

Hi @ikrama ,

 

It's because your customer[tags] is two times in code and since input is text type it will always override the previous selection.

 

 

To achieve it you should use radio button for which form will take only one value.

 

Replace your drop-down code with radio button and write your conditional code on their change event.

 

Rest will be same...

 

Hope it help...

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee

View solution in original post

Replies 4 (4)

gr_trading
Shopify Partner
1591 138 171

This is an accepted solution.

Hi @ikrama ,

 

It's because your customer[tags] is two times in code and since input is text type it will always override the previous selection.

 

 

To achieve it you should use radio button for which form will take only one value.

 

Replace your drop-down code with radio button and write your conditional code on their change event.

 

Rest will be same...

 

Hope it help...

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee
ikrama
Shopify Partner
7 0 0

Yes, Thank you. 

litlove
Visitor
1 0 0

I am trying to create a conditional question in my registration form, I tried using what this user has suggested but it is not working... I just need something simple:

Are you a boy or girl radio buttons and then if the user selects boy it shows a text field and if user selects girl it shows a different text field. Can you please show me how the code should look? When I use the example above and try switching to radio, it just shows all the information still.

gr_trading
Shopify Partner
1591 138 171

Im sorry dear I can help you to fix your existing code but writing code will require a job to offer.

 

Hope u understand.

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee