Hello!
I need help to modify the following JavaScript:
[HTML]<script language="javas cript">
var flds = "chk1,chk2,chk3 ,chk4".split(", ")
var vals = new Array(2,4,8,16)
var msgs = new Array();
msgs[0] = 'None checked';
msgs[2] = '1 checked';
msgs[4] = '2 checked';
msgs[6] = '2 & 1 checked';
msgs[8] = '3 checked';
msgs[10] = '3 & 1 checked';
msgs[12] = '3 & 2 checked';
msgs[14] = '3 & 2 & 1 checked';
msgs[16] = '4 checked';
msgs[18] = '4 & 1 checked';
msgs[20] = '4 & 2 checked';
msgs[22] = '4 & 2 & 1 checked';
msgs[24] = '4 & 3 checked';
msgs[26] = '4 & 3 & 1 checked';
msgs[28] = '4 & 3 & 2 checked';
msgs[30] = '4 & 3 & 2 & 1 checked';
function chkBoxProc (fld) {
var val = 0;
for (i=0;i<flds.len gth;i++) {
val += (fld.form.eleme nts[flds[i]].checked)?vals[i]:0;
}
document.getEle mentById ('msg').innerHT ML = msgs[val];
}
</script>
<form>
<input type="checkbox" name="chk1" onClick="chkBox Proc(this)">1<b r />
<input type="checkbox" name="chk2" onClick="chkBox Proc(this)">2<b r />
<input type="checkbox" name="chk3" onClick="chkBox Proc(this)">3<b r />
<input type="checkbox" name="chk4" onClick="chkBox Proc(this)">4<b r />
<span id="msg">None checked</span>
</form>[/HTML]
In the end I have about 10 checkboxes, which I want to display by this method. When I wrote this script in the way as you can see above it would take me at least 3 weeks.
Who can help me out to make the script more dynamic?
Finally I would replace the array values with some html-code which contains more form elements (checkboxes...) - is that possible too?
Thank you!
-w
I need help to modify the following JavaScript:
[HTML]<script language="javas cript">
var flds = "chk1,chk2,chk3 ,chk4".split(", ")
var vals = new Array(2,4,8,16)
var msgs = new Array();
msgs[0] = 'None checked';
msgs[2] = '1 checked';
msgs[4] = '2 checked';
msgs[6] = '2 & 1 checked';
msgs[8] = '3 checked';
msgs[10] = '3 & 1 checked';
msgs[12] = '3 & 2 checked';
msgs[14] = '3 & 2 & 1 checked';
msgs[16] = '4 checked';
msgs[18] = '4 & 1 checked';
msgs[20] = '4 & 2 checked';
msgs[22] = '4 & 2 & 1 checked';
msgs[24] = '4 & 3 checked';
msgs[26] = '4 & 3 & 1 checked';
msgs[28] = '4 & 3 & 2 checked';
msgs[30] = '4 & 3 & 2 & 1 checked';
function chkBoxProc (fld) {
var val = 0;
for (i=0;i<flds.len gth;i++) {
val += (fld.form.eleme nts[flds[i]].checked)?vals[i]:0;
}
document.getEle mentById ('msg').innerHT ML = msgs[val];
}
</script>
<form>
<input type="checkbox" name="chk1" onClick="chkBox Proc(this)">1<b r />
<input type="checkbox" name="chk2" onClick="chkBox Proc(this)">2<b r />
<input type="checkbox" name="chk3" onClick="chkBox Proc(this)">3<b r />
<input type="checkbox" name="chk4" onClick="chkBox Proc(this)">4<b r />
<span id="msg">None checked</span>
</form>[/HTML]
In the end I have about 10 checkboxes, which I want to display by this method. When I wrote this script in the way as you can see above it would take me at least 3 weeks.
Who can help me out to make the script more dynamic?
Finally I would replace the array values with some html-code which contains more form elements (checkboxes...) - is that possible too?
Thank you!
-w
Comment