问问select控件的失效问题

xqxxl 2006-07-04 10:09:23
<select name="test" onchane="Mdvalue()">
<option value="0">test1</option>
<option value="1">test2</option>
<option value="2">test3</option>
</select>

function Mdvalue()
{
if(document.form1.test.value == 1)
document.form1.test.disable = true;
}

当选择test2时,select变灰色,不让再其选择,ok,提交处理,但是有一问题,当选择test2时,select控件应当提交值1,但是测试下来提交了0,也就是说select关闭失效时,是不是只能提交第一个缺省值,有没有其它的方法,在线等待。
...全文
256 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wee_zhou 2006-07-04
  • 打赏
  • 举报
回复
document.form1.test.selectedIndex是获取当前选中的第几个选项,用document.form1.test.options[document.form1.test.selectedIndex].value来拿值
wee_zhou 2006-07-04
  • 打赏
  • 举报
回复
楼主还是注意一下书写吧, disabled onchange 都写漏了

<script>
function Mdvalue(){
if(document.form1.test.options[document.form1.test.selectedIndex].value == 1){
document.form1.test.disabled = true;
}
}
</script>

<form name="form1">
<select name="test" onchange="Mdvalue()">
<option value="0">test1</option>
<option value="1">test2</option>
<option value="2">test3</option>
</select>
</form>
MrYou 2006-07-04
  • 打赏
  • 举报
回复
先设一个变量var t,在每次onChange下拉框的时候现将value值赋给t,这样提交的时候提交t的值就可以了,楼主44
xqxxl 2006-07-04
  • 打赏
  • 举报
回复
select控件的值是从数据库中读出的,当读出test2的值时,控件应当变灰,不让选择,同时提交该页面的时候,select不能传值,而系统默认为0,提交了该控件的0值,所以也更改了我数据库中的值,变为0,当在此显示该页面时,变成了test1,大家有什么好的办法,从页面上解决这个问题,在控件变灰的状态下,让它提交1值,也可以。我试过在onsubmit函数中
document.form1.test.value = 1;
但是结果同上
xqxxl 2006-07-04
  • 打赏
  • 举报
回复
其它地方没有设置默认值,该值可以提交后存入数据库,值是从数据库中读出的
hbhbhbhbhb1021 2006-07-04
  • 打赏
  • 举报
回复
disabled是不能传值的,是不是其他地方设了默认值
wee_zhou 2006-07-04
  • 打赏
  • 举报
回复
没有完全看懂你的意思.
你试试把你需要的select控件值放到hidden里边处理,看看对你有无用?(<input type="hidden" >)
xqxxl 2006-07-04
  • 打赏
  • 举报
回复
wee_zhou(苦啤酒) 谢谢批评指教,我是图简单

楼上几位都是在select控件激活的状态下完成的,我的问题是

select控件的值是从数据库中读出的,当值为1时显示test2,控件应当变灰不可用,不让用户选择,当提交该页面的时候,失效的select不能传值,但是此时系统默认selelct控件值为0,提交了该控件的0值,所以也更改了我数据库中的值,变为0,应当是不能改变的。当再显示该页面时,却变成了test1。我想当select变灰显示test2时,虽然select控件失效,也提交1值,我试过在onsubmit函数中
document.form1.test.value = 1;
但是结果同上,还是提交的值0,大家都什么好的办法?

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧