Show/hide fields depending on select value

后端 未结 6 884
执念已碎
执念已碎 2020-11-30 04:38

I am trying to show and hide a few form fields depending on the value of one of my select fields. I am looking to use arrays to hold what should be shown and what should not

6条回答
  •  醉话见心
    2020-11-30 05:07

    There are a few different ways you could do this. The simplest is to have a few separate fieldsets, each one containing a single group of fields. Then, in jQuery, dependent on the select-menu's value you can show/hide these fieldsets, e.g.

    Note: For the above technique to be entirely unobtrusive you might want to dynamically build the select-menu with the names of all the different fieldsets.


    Alternatively you can prefix each fields name with a meaningful prefix, and then hide/show according to that attribute:

    
    
    
    
    
    
    
    
    
    
    

提交回复
热议问题