![](/img/trans.png)
[英]How to add new fields in registration form in joomla 2.5 default (com_users)
[英]customize registration form in joomla 2.5 - enable fields on the fly based on radio button value
我想自定義joomla注冊表格。 我添加了2個文本字段(公司名稱,增值稅號),並創建了帶有2個選項(業務用戶,普通用戶)的單選按鈕customerType。
現在,所有字段在窗體中都是可見的。 我想要的是,當用戶選擇業務用戶啟用2個文本字段時,以及當他選擇普通用戶立即禁用它們時。
我想我需要將javascript添加到表單中。 有人可以幫忙嗎?
謝謝!
# 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上創建函數,並在每個單選的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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.