dongmei8760 2013-04-04 22:36
浏览 74
已采纳

在joomla 2.5中自定义注册表单 - 根据单选按钮值动态启用字段

I want to customize joomla registration form. I ve added 2 text fields (company name, vat_number) and i ve created a radio button customerType with 2 options(business user, normal user).

Now all the fields are visible in the form. What i want is, when the user selects business user to enable the 2 text fields and when he selects normal user to disable them on the fly.

I guess i need to add javascript to the form. Can anyone help?

Thank you!

  • 写回答

2条回答 默认 最新

  • dongmiao260399 2013-04-05 05:11
    关注

    I have done this in here

    # Script to show hide div
    <script type="text/javascript">
        function show(obj) {
    
        if(obj == 'farmer')
        {
            document.getElementById('SkiDiv1').style.display = 'block';
            document.getElementById('SkiDiv2').style.display = 'none';
        }
    
        if(obj == 'landowner')
        {
            document.getElementById('SkiDiv2').style.display = 'block';
            document.getElementById('SkiDiv1').style.display = 'none';
        }
        if(obj == 0)
        {
            document.getElementById('SkiDiv2').style.display = 'none';
            document.getElementById('SkiDiv1').style.display = 'none';
        }
    
        }
        </script>
    
    # Selct from dropdown
    <select  name="siteusertype" class="inputbox1 required" onchange="show(this.value)">
        <option id="selectuser" value="0">Select User</option> 
        <option value="farmer">Are you a Farmer ?</option>
        <option value="landowner">Are you a Landowner ?</option>
    </select>
    
    # Both div with different IDs
    <div id="SkiDiv1"> User 1 field </div>
    <div id="SkiDiv2"> User 2 field </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?