首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

select box的有关问题,当其中一个选项被选上,页面要出现一个textfield

2012-01-08 
求一个select box的问题,当其中一个选项被选上,页面要出现一个textfield.这是selectbox的源码:tdselect

求一个select box的问题,当其中一个选项被选上,页面要出现一个textfield.
这是selectbox的源码:
<td>
<select name="carrierName">
<% String selectedOrderCarrierName = requestFrmObj.getCarrierName(); %>
<option value="Toll Online" <% if(selectedOrderCarrierName.equalsIgnoreCase("Toll Online")){ %> selected <% } %>>Toll Online</option>
<option value="Toll Priority" <% if(selectedOrderCarrierName.equalsIgnoreCase("Toll Priority")){ %> selected <% } %>>Toll Priority</option>
<option value="Australia Post" <% if(selectedOrderCarrierName.equalsIgnoreCase("Australia Post")){ %> selected <% } %>>Australia Post</option>
<option value="Other" <% if(selectedOrderCarrierName.equalsIgnoreCase("Sent")){ %> selected <% } %>>Other</option>
</select>  
</td>

当"other"被选中时,页面中要出现一个textfield,用来写出carriername,然后这个textfield里的carriername要能提交到javabean相对的getCarrierName中.用javascript能实现么?大家给些设计意见可以么?最好是源程序啦!!

[解决办法]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function show(){
var carrierName=document.getElementById("carrierName");
var b=document.getElementsByTagName("BODY")[0];
for(var i=0;i<carrierName.options.length;i++){
if(carrierName.options[i].value==2){
var text=document.createElement("input");
text.type = "text"; 
text.value=carrierName.options[i].value;
b.appendChild(text);

}
}

}
</script>
</HEAD>

<BODY>
<select id="carrierName" onChange="javaScript:show();">
<option value="1">1</option>
<option value="2">2</option>
</select>
</BODY>
</HTML>
就是个样子而已,希望有帮助
[解决办法]
<td> 
<select name="carrierName"> 
<% String selectedOrderCarrierName = requestFrmObj.getCarrierName(); %> 
<option value="Toll Online" <% if(selectedOrderCarrierName.equalsIgnoreCase("Toll Online")){ %> selected <% } %>>Toll Online </option> 
<option value="Toll Priority" <% if(selectedOrderCarrierName.equalsIgnoreCase("Toll Priority")){ %> selected <% } %>>Toll Priority </option> 
<option value="Australia Post" <% if(selectedOrderCarrierName.equalsIgnoreCase("Australia Post")){ %> selected <% } %>>Australia Post </option> 
<option value="Other" <% if(selectedOrderCarrierName.equalsIgnoreCase("Sent")){ %> selected <% } %>>Other </option> 
</select>
</td> 
<!--让文本框隐藏 -->
<input type="text" value="xxxxx" style="display:none;" id="inp" />
<script type="text/javascript">
//得到select对象
var selects = document.getElementById("carrierName");
//如果默认选择Other 的时候 让文本框显示
if(selects.value == 'Other'){
var inp = document.getElementById("inp");
inp.style.display = "block";


}
</script>
[解决办法]
//得到select对象 
var selects = document.getElementById("carrierName"); 
这改成
var selects = document.forms[0].carrierName;
[解决办法]
不好意思,刚才发的那个有点问题,该了该:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function show(){
var carrierName=document.getElementById("carrierName");
var b=document.getElementsByTagName("BODY")[0];
if(carrierName.selectedIndex==1){
var text=document.createElement("input");
text.type = "text"; 
text.id="text";
text.value=carrierName.options[carrierName.selectedIndex].value;
b.appendChild(text);
}
}
</script>
</HEAD>

<BODY>
<select id="carrierName" onChange="javaScript:show();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</BODY>
</HTML>
[解决办法]

HTML code
<input type="button" value="插入" onclick="insert_row()"> <table name='tbl' id="tbl" border="1" width=300> </table> <script>    var i=0    function insert_row(){        i ++        R = tbl.insertRow()        C = R.insertCell()        C.innerHTML = "<input type='file' name='file' >"        C = R.insertCell()        C.innerHTML = "文件" + i        C = R.insertCell()        C.innerHTML = "<input type='button'  value='删除' onclick='tbl.deleteRow("+(i-1)+")'>"    }</script>
[解决办法]
下面的代码可以实现你显示文本框的功能,不过我觉得要是把文本框和选择框的name定义成一样的话提交后获取会
出问题,建议还是使用不同的名字
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<script type="text/javascript">

function changeSelect(){
var selects = document.getElementById("test").value; 
var inp = document.getElementById("inp");
if(selects == 'Other'){
inp.style.display = "block";
}else{
inp.style.display = "none";
}
}
  
</script> 


<title>无标题文档 </title> 
</head> 

<body> 
<td>
<select name="carrierName" id="test" onchange="changeSelect()">

<option value="Toll Online" selected > Toll Online </option>
<option value="Toll Priority" > Toll Priority </option>
<option value="Australia Post" >Australia Post </option>
<option value="Other" >Other </option>
</select>


</td>
<!--让文本框隐藏 -->
<input type="text" value="ok" name="carrierName" style="display:none;" id="inp" />


</body> 
</html>

热点排行