Why does this simple code not work in Firefox and Chrome but it works on IE? What's wrong with this script? I just want to find a way too get selected checkbox text (or label) and use it a $_post
on another page.
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<script type="text/javascript" language="javascript">
function ReadCheckbox()
{
var temp = '';
var radio;
var popupTag ;
for (var i=1 ; i<5 ; i++) {
radio = document.getElementById('chk'+i);
if(radio.checked == true){temp += radio.value}
}
document.getElementById('aaaa').value = temp;
}
</script>
</head>
<body>
<label>What is your Site Address ?</label><br/>
<label>NetNic.ir</label><input id="chk1" type="checkbox" value="NetNic.ir" />
<label>SarirWeb.Com</label><input id="chk2" type="checkbox" value="SarirWeb.Com"/>
<label>LearnCD.ir</label><input id="chk3" type="checkbox" value="LearnCD.ir"/>
<label>AnimLand.ir</label><input id="chk4" type="checkbox" value="AnimLand.ir"/>
<br />
<br/>
<textarea rows="2" name="aaaa" cols="20"></textarea>
<input type="button" onclick="ReadCheckbox()" value="ثبت" style="height:32px; width:83px;"/>
name="aaaa"
is not an id. So getElementById('aaaa')
will not find it.
尝试:
<textarea rows="2" name="aaaa" id="aaaa" cols="20"></textarea>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.