日期:2014-05-16  浏览次数:20394 次

求助:radio选择后 其中一个文本框需要填写数据才可提交
<script   language="javascript">
<!--
function   CheckForm()
{  
var flag = true;
var allRadio = document.form.elements["a_dzsw"];
for(var i = 0;i < allRadio.length;i++){
   if(allRadio[i].checked==true && allRadio[i].value =="已开展"){
    flag = false;
   }
}
if (!flag){
 alert("请选择")
}
 return flag
}
-->
</script> 这是代码:目前做到的是一个radio如果选择了“已开展”就会弹出个对话框    可是想做到的是 radio选择“已开展”并且另外一个字段填写了数据后就可以提交 ,现在这样的效果是不管另外那个字段是否有数据都会拒绝提交

------解决方案--------------------
另外那个字段,在哪里?是什么TAG?
------解决方案--------------------
你在方法里再验证那个字段填写了没有 
如果字段和单选框都符合要求返回true
否则返回false
试试
------解决方案--------------------
试试把下面的方法加到你的代码里:


// 找出 name 为a_qyxxhjh_nd 的 input, 注意它的id是A1
var input = document.getElementById("A1");  

if ( ... ) {  // 检查 input.value 是否填写了数据
  //todo
}

------解决方案--------------------
  if(allRadio[i].checked==true && allRadio[i].value =="已开展"){
        //这里获取a_qyxxhjh_nd.text 值
     if(textValue!="") 
           return true  //可以提交
     else 
           return false //不可以提交
   }
}
不知道理解的是否正确
------解决方案--------------------
都10天以前的帖了,是不是该结了?

  <table width="588" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="80" height="24">
<input type="radio" name="a_dzsw" value="已开展" onclick=hh.style.display='block'>
已开展 
</td>
<td width="505">
<div id=hh style=display:none>
年度:<input type="text" name="a_qyxxhjh_nd" size="12" id="A1" value=""  class="input_on" onfocus="this.className='input_out';this.onmouseout=''" onblur="this.className='input_off';this.onmouseout=function(){this.className='input_on'};" onmousemove="this.className='input_move'" onmouseout="this.className='input_on'" />
名称: <input type="text" name="a_qyxxhjh_mc" size="12" value="" id="A1" class="input_on" onfocus="this.className='input_out';this.onmouseout=''" onblur="this.className='input_off';this.onmouseout=function(){this.className='input_on'};" onmousemove="this.className='input_move'" onmouseout="this.className='input_on'" />
</div>
</td>
</tr>
<tr>
<td height="24" colspan="2">
<input type="radio" name="a_dzsw" value="未开展" checked  onclick=hh.style.display='none'>
未开展 
</td>
</tr>
  </table>
<INPUT TYPE="button" VALUE=" 提交" ONCLICK="CheckForm()">