2013-04-04 22:36
浏览 64

在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!

图片转代码服务由CSDN问答提供 功能建议

我想自定义joomla注册表。 我添加了2个文本字段(公司名称,vat_number)和i ve 创建了一个带有2个选项的单选按钮customerType(业务用户,普通用户)。

现在所有字段都在表单中可见。 我想要的是,当用户选择业务用户启用2个文本字段时,以及当他选择普通用户即时禁用它们时。

我想我需要添加javascript到 形成。 有人可以帮忙吗?


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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';
    # 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>
    # Both div with different IDs
    <div id="SkiDiv1"> User 1 field </div>
    <div id="SkiDiv2"> User 2 field </div>
    打赏 评论
  • dongtan9518 2013-04-04 22:50

    1- Make a function on javascript and reference in onClick event of each radio.
    2- Inside javascript function use getElementById function of javascript to set visible or invisible any html element of form according user selection.

    function hideElement()
       if (user select you want)
         //if you want display element

    see example:

    打赏 评论

相关推荐 更多相似问题