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


customize registration form in joomla 2.5 - enable fields on the fly based on radio button value

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

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

我想我需要添加javascript的形式。有人能帮忙吗?

谢谢!

我在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-在javascript上创建一个函数,并在每个radio的onClick事件中引用。
2-在javascript函数中使用javascript的getElementById函数来设置可见或不可见的任何html元素的形式,根据用户的选择。

function hideElement()
{
   if (user select you want)
      document.getElementById("element-to-hide").style.visibility="hidden";
   else
     //if you want display element
      document.getElementById("element-to-display").style.visibility="visible";
}

参见示例:
http://www.w3schools.com/jsref/met_doc_getelementbyid.asp
http://www.w3schools.com/jsref/prop_style_visibility.asp