ใน Chrome ทำงาน
ใน firefox ไม่ทำงาน
ต้องแก้โค้ดตรงไหนครับ
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form name="form1" action="" method="post">
<b>Test Select</b>
<p>
<label><input type="radio" name="size" value="1" /> chioce 1 </label>
<label><input type="radio" name="size" value="2" /> choice 2 </label><br>
<table>
<tr><td>field 1 </td><td><input type="text" name="field1" value=""></td></tr>
<tr><td>field 2</td><td><input type="text" name="field2" value=""></td></tr>
</table>
<label><input type="submit" name="cal" value="คำนวน!!"></label>
<label><input type="button" value="ล้างทั้งหมด" onclick="clear_form_elements(this.form)" /></label>
</form>
<script type="text/javascript">
var sz = document.forms['form1'].elements['size'];
for (var i=0, len=sz.length; i<len; i++) {
sz[i].onclick = function() {
if (sz.value == 1){
this.form.field1.value = 4032;
this.form.field2.value = 1120;
}
else if (sz.value == 2)
{
this.form.field1.value = 7056;
this.form.field2.value = 1960;
}
};
}
function clear_form_elements(ele) {
tags = ele.getElementsByTagName('input');
for(i = 0; i < tags.length; i++) {
switch(tags[i].type) {
case 'password':
case 'text':
tags[i].value = '';
break;
case 'checkbox':
case 'radio':
tags[i].checked = false;
break;
}
}
tags = ele.getElementsByTagName('select');
for(i = 0; i < tags.length; i++) {
if(tags[i].type == 'select-one') {
tags[i].selectedIndex = 0;
}
else {
for(j = 0; j < tags[i].options.length; j++) {
tags[i].options[j].selected = false;
}
}
}
tags = ele.getElementsByTagName('textarea');
for(i = 0; i < tags.length; i++) {
tags[i].value = '';
}
}
</script>
</body>
</html>
Javescript onclick ไม่ทำงานบน Firefox
ใน firefox ไม่ทำงาน
ต้องแก้โค้ดตรงไหนครับ
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form name="form1" action="" method="post">
<b>Test Select</b>
<p>
<label><input type="radio" name="size" value="1" /> chioce 1 </label>
<label><input type="radio" name="size" value="2" /> choice 2 </label><br>
<table>
<tr><td>field 1 </td><td><input type="text" name="field1" value=""></td></tr>
<tr><td>field 2</td><td><input type="text" name="field2" value=""></td></tr>
</table>
<label><input type="submit" name="cal" value="คำนวน!!"></label>
<label><input type="button" value="ล้างทั้งหมด" onclick="clear_form_elements(this.form)" /></label>
</form>
<script type="text/javascript">
var sz = document.forms['form1'].elements['size'];
for (var i=0, len=sz.length; i<len; i++) {
sz[i].onclick = function() {
if (sz.value == 1){
this.form.field1.value = 4032;
this.form.field2.value = 1120;
}
else if (sz.value == 2)
{
this.form.field1.value = 7056;
this.form.field2.value = 1960;
}
};
}
function clear_form_elements(ele) {
tags = ele.getElementsByTagName('input');
for(i = 0; i < tags.length; i++) {
switch(tags[i].type) {
case 'password':
case 'text':
tags[i].value = '';
break;
case 'checkbox':
case 'radio':
tags[i].checked = false;
break;
}
}
tags = ele.getElementsByTagName('select');
for(i = 0; i < tags.length; i++) {
if(tags[i].type == 'select-one') {
tags[i].selectedIndex = 0;
}
else {
for(j = 0; j < tags[i].options.length; j++) {
tags[i].options[j].selected = false;
}
}
}
tags = ele.getElementsByTagName('textarea');
for(i = 0; i < tags.length; i++) {
tags[i].value = '';
}
}
</script>
</body>
</html>