Menu
If I want to code so that when I tick the checkbox it “adds” the value to the textfied which is readonly how do I do that?? Basically I’m building a simple store page where I click on the checkbox to confirm that I want to get this and that triggers the bottom textfield to add the certain value but obviously there are more than one. I’ve been trying for hours but can’t get it to work >< ?
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var names=['ch1','ch2','ch3'];
function calc(f){
var def=Number(f['res'].defaultValue);
for(var i=0;i<names.length;i++){
f[names[i]].checked?def+=Number(f[names[i]].value):null;
}
f['res'].value=def
}
</script>
</head>
<body>
<form>
<input name="ch1" type="checkbox" value="10" onclick="calc(this.form)">+10<br>
<input name="ch2" type="checkbox" value="20" onclick="calc(this.form)">+20<br>
<input name="ch3" type="checkbox" value="50" onclick="calc(this.form)">+50
<br>
<br>
Result = <input type="text" name="res" value="100" readonly="true">
</form>
</body>
</html>
[/code]
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var names=['ch1','ch2','ch3'];
function calc(f){
var f2=document['form2']
var def=Number(f2['res'].defaultValue);
for(var i=0;i<names.length;i++){
f[names[i]].checked?def+=Number(f[names[i]].value):null;
}
f2['res'].value=def
}
</script>
</head>
<body>
<form>
<input name="ch1" type="checkbox" value="10" onclick="calc(this.form)">+10<br>
<input name="ch2" type="checkbox" value="20" onclick="calc(this.form)">+20<br>
<input name="ch3" type="checkbox" value="50" onclick="calc(this.form)">+50
<br>
<br>
</form>
<form name="form2">
Result = <input type="text" name="res" value="100" readonly="true">
</form>
</body>
</html>
[/code]
<td width="230"><input type="image" name="imageField" src="images/muse_absolution.jpg" /></td>
<td width="40"> </td>
<td width="280"><h3>Absolution</h3>
<ol>
<li>intro (instrumental)</li>
<li>time is running out</li>
<li>sing for absolution</li>
<li>stockholm syndrome</li>
<li>falling away with you</li>
<li>interlude (instrumental)</li>
<li>hysteria</li>
<li>blackout</li>
<li>butterflies and hurricanes</li>
<li>the small print</li>
<li>endlessly</li>
<li>thoughts of a dying atheist</li>
<li>ruled by secrecy</li>
</ol>
</td>
</tr>
<tr>
<td colspan="3" class="order_chk">
<form>
<input name="music_chk15" type="checkbox" value="20" onclick="enablePurchaseButton(this,1); totalCost(this.form)" />Order This Album
</form>
</td>
</tr>
0.1.9 — BETA 5.20