View Full Version : If statement
jblain11
09-06-2001, 05:02 PM
This will sound kind of confusing but I'll try to explain.
I am trying to work out an if statement that will allow me to add the value of a textbox (given by the user) to the values of other textboxes.
The only textboxes I want the sum of are those whose corresponding checkboxes are not checked.
Dr. Web
09-06-2001, 05:10 PM
easier to see the page along with the description of your objective. Can you post the url?
jblain11
09-06-2001, 05:20 PM
actually I am going to pull the script into a Adobe Acrobat PDF file.
I have found a way to use a different if statement if it will be easier. So just an if statement that will add the values of textboxes if corresponding checkboxes are selected. and then subtract them from the total number of 'miles' can I upload pdf files to this forum, or do I need to zip them?
_mrkite
09-06-2001, 05:43 PM
<html>
<head><title>untitled</title>
<script language="JavaScript" type="text/javascript">
function addUnchecked(f) {
var currVal, total=0;
for (var i=0; i<f.elements.length; i++) {
if (f.elements[i].type == 'text' && f.elements[i].name != 'total'
&& f.elements[i+1].type == 'checkbox' && !f.elements[i+1].checked ) {
currVal = f.elements[i].value;
if (currVal) {
if (isNaN(parseInt(currVal))) {
alert('Please enter a valid number.');f.elements[i].focus();f.elements[i].select();return;
} else {
total += parseInt(currVal);
}
}
}
f.total.value = total;
}
}
</script>
</head>
<body bgcolor="ivory" onload="document.forms[0].reset()">
<div align="center"><br><br><br>
<table cellspacing="0" cellpadding="5" border="3" bordercolor="black" bgcolor="tan">
<form>
<tr><th>enter value</th><th>don't add</th></tr>
<tr><td><b>1</b><input type="text"></td><td align="center"><input type="checkbox"></td></tr>
<tr><td><b>2</b><input type="text"></td><td align="center"><input type="checkbox"></td></tr>
<tr><td><b>3</b><input type="text"></td><td align="center"><input type="checkbox"></td></tr>
<tr><td colspan="2" bgcolor="black"><br></td></tr>
<tr><td><input type="button" value="Add Unchecked" onclick="addUnchecked(this.form)"></td>
<td><b>sum</b> <input name="total" type="text" size="8"></td></tr></form></table>
</div>
</body>
</html>
jblain11
09-06-2001, 05:59 PM
Thanks buddy worked great.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.