ASP如何通过点击checkbox赋值给文本框
我想实现通过点击checkbox,判断如果勾上,就把数据库的值赋给文本框,没有勾上,就清空文本框.代码如下,但运行没有反应,应如何修改,望指教<scriptlanguag...
我想实现通过点击checkbox,判断如果勾上,就把数据库的值赋给文本框,没有勾上,就清空文本框.代码如下,但运行没有反应,应如何修改,望指教
<script language="JavaScript">
function checkuse(sub1,sub2,sub3,sub4,sub5)
{
var e=document.getElementByName("chkUse");
var text=document.getElementsByType("text");
var subval=new Array(sub1,sub2,sub3,sub4,sub5);
if(e.checked==true)
{
for(i=0;i<text.length;i++)
{
text[i].value=subval[i];
}
}
else
{
for(i=0;i<text.length;i++)
{
text[i].value=null
}
}
}
</script>
<form action="aaa.asp" method="post" name="form1">
<input id="chkUse" name="chkUse" type="checkbox" onClick="checkuse(<%rs("firstname")%>,<%rs("lastname")%>,<%rs("addr")%>,<%rs("city")%>,<%rs("country")%>)">
<input name="firstname" type="text" id="firstname" size="40">
<input name="lastname" type="text" id="lastname" size="40">
<input name="address" type="text" id="address" size="40">
<input name="city" type="text" id="city" size="40">
<input name="country" type="text" id="country" size="40">
<input type="submit" name="Submit" value="COMPLETE">
</form> 展开
<script language="JavaScript">
function checkuse(sub1,sub2,sub3,sub4,sub5)
{
var e=document.getElementByName("chkUse");
var text=document.getElementsByType("text");
var subval=new Array(sub1,sub2,sub3,sub4,sub5);
if(e.checked==true)
{
for(i=0;i<text.length;i++)
{
text[i].value=subval[i];
}
}
else
{
for(i=0;i<text.length;i++)
{
text[i].value=null
}
}
}
</script>
<form action="aaa.asp" method="post" name="form1">
<input id="chkUse" name="chkUse" type="checkbox" onClick="checkuse(<%rs("firstname")%>,<%rs("lastname")%>,<%rs("addr")%>,<%rs("city")%>,<%rs("country")%>)">
<input name="firstname" type="text" id="firstname" size="40">
<input name="lastname" type="text" id="lastname" size="40">
<input name="address" type="text" id="address" size="40">
<input name="city" type="text" id="city" size="40">
<input name="country" type="text" id="country" size="40">
<input type="submit" name="Submit" value="COMPLETE">
</form> 展开
1个回答
展开全部
你试试
<script language="JavaScript">
function checkuse(sub1,sub2,sub3,sub4,sub5)
{
var e=document.getElementById("chkUse");
var text=document.getElementsByTagName("input");
var subval=new Array(sub1,sub2,sub3,sub4,sub5);
if(e.checked)
{
//alert(text.length)
for(i=0;i<=text.length;i++)
{
if(text[i].type=="text")
text[i].value=subval[i-1];
}
}
else
{
for(i=1;i<text.length;i++)
{
if(text[i].type=="text")
text[i].value="";
}
}
}
</script>
<form action="aaa.asp" method="post" name="form1">
<input id="chkUse" name="chkUse" type="checkbox" onclick="checkuse(<%rs("firstname")%>,<%rs("lastname")%>,<%rs("addr")%>,<%rs("city")%>,<%rs("country")%>)">
<input name="firstname" type="text" id="firstname" size="40">
<input name="lastname" type="text" id="lastname" size="40">
<input name="address" type="text" id="address" size="40">
<input name="city" type="text" id="city" size="40">
<input name="country" type="text" id="country" size="40">
<input type="submit" name="Submit" value="COMPLETE">
</form>
<script language="JavaScript">
function checkuse(sub1,sub2,sub3,sub4,sub5)
{
var e=document.getElementById("chkUse");
var text=document.getElementsByTagName("input");
var subval=new Array(sub1,sub2,sub3,sub4,sub5);
if(e.checked)
{
//alert(text.length)
for(i=0;i<=text.length;i++)
{
if(text[i].type=="text")
text[i].value=subval[i-1];
}
}
else
{
for(i=1;i<text.length;i++)
{
if(text[i].type=="text")
text[i].value="";
}
}
}
</script>
<form action="aaa.asp" method="post" name="form1">
<input id="chkUse" name="chkUse" type="checkbox" onclick="checkuse(<%rs("firstname")%>,<%rs("lastname")%>,<%rs("addr")%>,<%rs("city")%>,<%rs("country")%>)">
<input name="firstname" type="text" id="firstname" size="40">
<input name="lastname" type="text" id="lastname" size="40">
<input name="address" type="text" id="address" size="40">
<input name="city" type="text" id="city" size="40">
<input name="country" type="text" id="country" size="40">
<input type="submit" name="Submit" value="COMPLETE">
</form>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询