Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-02-2011, 08:08 PM   PM User | #1
ten3six
New Coder

 
Join Date: Jan 2011
Location: fort worth, tx
Posts: 11
Thanks: 2
Thanked 0 Times in 0 Posts
ten3six is an unknown quantity at this point
Button is not working

I've never had this problem in the past and I am now stumped. I've written a fairly long script to calculate numbers for a web based Diabetes calculator but for some reason the "Calculate" button does nothing when using Chrome, Opera or Safari for iOS. It does work when using IE, Firefox and Safari for PC. I've looked everywhere and found nothing but some references to an 'onclick' problem in Chrome. My problem is that the same method has always worked in the past and is still working in those scripts now so that can't be the issue. What is different about THIS button that is breaking it?

Button WORKS here (IE, Chrome, Firefox, Safari-PC & iOS & Opera): http://jdrinc.webatu.com/FICC.html

But DOES NOT work here (Chrome, Safari-iOS & Opera): http://jdrinc.webatu.com/D-Calc.html

The second link DOES work in IE, Firefox & Safari-PC.

I don't see a difference in the method that I'm using in either of these. Does anyone know what I am doing wrong?

Here is the html with the script that is NOT working:
Code:
<html>
	<head>
		<title>
			D-Calc
		</title>
		<style type="text/css">
			table
				{
					border:2px solid black;
					border-collapse:collapse;
				}
			th
				{
					border:2px solid black;
					border-collapse:collapse;
					font-family: Arial, Helvetica, sans-serif;
					text-align: left;
					font-weight: bold;
				}
			td
				{
					border:2px solid black;
					border-collapse:collapse;
					font-family: Arial, Helvetica, sans-serif;
					text-align: left;
					font-weight: bold;
				}
			.inputlabel
				{
					background-color: #6CC417;
				}
			.outputlabel
				{
					background-color: #6698FF;
				}
			.inputbox
				{
					border:0px inset blue;
					background-color: #FFFFFF;
					border-color: #FFFFFF;
					text-align: center;
					font-weight: bold;
					width: 100px;
				}
			.outputbox
				{
					border:0px inset blue;
					background-color: #FFFFFF;
					border-color: #FFFFFF;
					text-align: center;
					font-weight: bold;
					width: 100px;
				}
		</style>
		<script type="text/javascript">
			function Calculate()
			{
				//input variables
				var B01, B02, B03, B04, B05, B06, B07, B08, B09, B10, B11
				//output variables
				var B12, B13, B14, B15, B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26
				//correction sensitivity variable
				var CSV
				//new blood glucose
				var NBG
				//bloodsugar-carbohydrate ratio
				var BCR
				B01=eval(document.DCalcForm.B01.value);
				B02=eval(document.DCalcForm.B02.value);
				BCR=(B02/B01);
				B03=eval(document.DCalcForm.B03.value);
				B04=eval(document.DCalcForm.B04.value);
				B05=eval(document.DCalcForm.B05.value);
				B06=eval(document.DCalcForm.B06.value);
				B07=eval(document.DCalcForm.B07.value);
				B08=eval(document.DCalcForm.B08.value);
				B09=eval(document.DCalcForm.B09.value);
				B10=eval(document.DCalcForm.B10.value);
				B11=eval(document.DCalcForm.B11.value);
				B12=(B10*(B03/100));
				B13=(B11*(B04/100));
				B14=(B09+B12+B13);
				B15=(B09);
				B16=(B12+B13);
				if (B07<(B05+(B06+1)) && B07>(B05-(B06+1)))
				{
					CSV=(0);
				}
				else if (B07>(B05+B06))
				{
					CSV=(B06);
				}
				else if (B07<(B05-B06))
				{
					CSV=(-1*B06);
				}
				if (CSV==0)
				{
					B17=0;
				}
				else
				{
					B17=((B07-(B05+CSV))/B02);
				}
				B18=((B12*(B03/100))/B01);
				B19=((B13*(B04/100))/B01);
				B20=(B09/B01);
				if (CSV=0)
				{
					B21=((B18+B19+B20)-B08);
				}
				else
				{
					B21=((B17+B18+B19+B20)-B08);
				}
				B22=((B17+B20)-B08);
				B23=(B18+B19);
				if (B21==0)
				{
					B24=0;
				}
				else
				{
					B24=((B22/B21)*100);
				}
				if (B21==0)
				{
					B25=0;
				}
				else
				{
					B25=((B23/B21)*100);
				}
				NBG=(B07+((B09+B12+B13)*BCR));
				if (B07<(B05+(B06+1)) && B07>(B05-(B06+1)))
				{
					CSV=(0);
				}
				else if (B07>(B05+B06))
				{
					CSV=(B06);
				}
				else if (B07<(B05-B06))
				{
					CSV=(-1*B06);
				}
				if (CSV==0)
				{
					B26=0;
				}
				else
				{
					B26=(((B05+CSV)-NBG)/BCR);
				}
				document.DCalcForm.B12.value=(Math.round(B12*100))/100 + ' g';
				document.DCalcForm.B13.value=(Math.round(B13*100))/100 + ' g';
				document.DCalcForm.B14.value=(Math.round(B14*100))/100 + ' g';
				document.DCalcForm.B15.value=(Math.round(B15*100))/100 + ' g';
				document.DCalcForm.B16.value=(Math.round(B16*100))/100 + ' g';
				if (B17<0)
				{
					document.DCalcForm.B17.value='0 unit(s)';
				}
				else
				{
					document.DCalcForm.B17.value=(Math.round(B17*100))/100 + ' unit(s)';
				}
				if (B18<0)
				{
					document.DCalcForm.B18.value='0 unit(s)';
				}
				else
				{
					document.DCalcForm.B18.value=(Math.round(B18*100))/100 + ' unit(s)';
				}
				if (B19<0)
				{
					document.DCalcForm.B19.value='0 unit(s)';
				}
				else
				{
					document.DCalcForm.B19.value=(Math.round(B19*100))/100 + ' unit(s)';
				}
				if (B20<0)
				{
					document.DCalcForm.B20.value='0 unit(s)';
				}
				else
				{
					document.DCalcForm.B20.value=(Math.round(B20*100))/100 + ' unit(s)';
				}
				if (B21<0)
				{
					document.DCalcForm.B21.value='0 unit(s)';
				}
				else
				{
					document.DCalcForm.B21.value=(Math.round(B21*100))/100 + ' unit(s)';
				}
				if (B22<0)
				{
					document.DCalcForm.B22.value='0 unit(s)';
				}
				else
				{
					document.DCalcForm.B22.value=(Math.round(B22*100))/100 + ' unit(s)';
				}
				if (B23<0)
				{
					document.DCalcForm.B23.value='0 unit(s)';
				}
				else
				{
					document.DCalcForm.B23.value=(Math.round(B23*100))/100 + ' unit(s)';
				}
				if (B24>100)
				{
					document.DCalcForm.B24.value='100 %';
				}
				else if (B24<0)
				{
					document.DCalcForm.B24.value='0 %';
				}
				else
				{
					document.DCalcForm.B24.value=(Math.round(B24*100))/100 + ' %';
				}
				if (B25>100)
				{
					document.DCalcForm.B25.value='100 %';
				}
				else if (B25<0)
				{
					document.DCalcForm.B25.value='0 %';
				}
				else
				{
					document.DCalcForm.B25.value=(Math.round(B25*100))/100 + ' %';
				}
				if (B26<0)
				{
					document.DCalcForm.B26.value='0.00 g';
				}
				else
				{
					document.DCalcForm.B26.value=(Math.round(B26*100))/100 + ' g';
				}
				//				document.write('B01 = '+B01+'<br>');
				//				document.write('B02 = '+B02+'<br>');
				//				document.write('B03 = '+B03+'<br>');
				//				document.write('B04 = '+B04+'<br>');
				//				document.write('B05 = '+B05+'<br>');
				//				document.write('B06 = '+B06+'<br>');
				//				document.write('B07 = '+B07+'<br>');
				//				document.write('B08 = '+B08+'<br>');
				//				document.write('B09 = '+B09+'<br>');
				//				document.write('B10 = '+B10+'<br>');
				//				document.write('B11 = '+B11+'<br>');
				//				document.write('B12 = '+B12+'<br>');
				//				document.write('B13 = '+B13+'<br>');
				//				document.write('B14 = '+B14+'<br>');
				//				document.write('B15 = '+B15+'<br>');
				//				document.write('B16 = '+B16+'<br>');
				//				document.write('B17 = '+B17+'<br>');
				//				document.write('B18 = '+B18+'<br>');
				//				document.write('B19 = '+B19+'<br>');
				//				document.write('B20 = '+B20+'<br>');
				//				document.write('B21 = '+B21+'<br>');
				//				document.write('B22 = '+B22+'<br>');
				//				document.write('B23 = '+B23+'<br>');
				//				document.write('B24 = '+B24+'<br>');
				//				document.write('B25 = '+B25+'<br>');
				//				document.write('B26 = '+B26+'<br>');
				//				document.write('BCR = '+BCR+'<br>');
				//				document.write('CSV = '+CSV+'<br>');
				//				document.write('NBG = '+NBG+'<br>');
			}
		</script>
	</head>
	<body>
		<center>
		<form name=DCalcForm>
			<table name="table" id="table" class="table">
				<tr name="01" id="01" class="">
					<td name="A01" id="A01" class="inputlabel">
						&nbsp;INSULIN/CARBOHYDRATE RATIO&nbsp;
					</td>
					<td name="B01" id="B01" class="">
						<input name="B01" id="B01" class="inputbox" value="10" type="number">
					</td>
					<td name="C01" id="C01" class="">
					</td>
				</tr>
				<tr name="02" id="02" class="">
					<td name="A02" id="A02" class="inputlabel">
						&nbsp;INSULIN/BG RATIO&nbsp;
					</td>
					<td name="B02" id="B02" class="">
						<input name="B02" id="B02" class="inputbox" value="35" type="number">
					</td>
					<td name="C02" id="C02" class="">
					</td>
				</tr>
				<tr name="03" id="03" class="">
					<td name="A03" id="A03" class="inputlabel">
						&nbsp;PROTEIN RATIO&nbsp;
					</td>
					<td name="B03" id="B03" class="">
						<input name="B03" id="B03" class="inputbox" value="40" type="number">
					</td>
					<td name="C03" id="C03" class="">
					</td>
				</tr>
				<tr name="04" id="04" class="">
					<td name="A04" id="A04" class="inputlabel">
						&nbsp;FAT RATIO&nbsp;
					</td>
					<td name="B04" id="B04" class="">
						<input name="B04" id="B04" class="inputbox" value="10" type="number">
					</td>
					<td name="C04" id="C04" class="">
					</td>
				</tr>
				<tr name="05" id="05" class="">
					<td name="A05" id="A05" class="inputlabel">
						&nbsp;TARGET BLOOD GLUCOSE&nbsp;
					</td>
					<td name="B05" id="B05" class="">
						<input name="B05" id="B05" class="inputbox" value="100" type="number">
					</td>
					<td name="C05" id="C05" class="">
					</td>
				</tr>
				<tr name="06" id="06" class="">
					<td name="A06" id="A06" class="inputlabel">
						&nbsp;CORRECTION RANGE/SENSITIVETY&nbsp;
					</td>
					<td name="B06" id="B06" class="">
						<input name="B06" id="B06" class="inputbox" value="20" type="number">
					</td>
					<td name="C06" id="C06" class="">
					</td>
				</tr>
				<tr name="07" id="07" class="">
					<td name="A07" id="A07" class="inputlabel">
						&nbsp;CURRENT BLOOD GLUCOSE&nbsp;
					</td>
					<td name="B07" id="B07" class="">
						<input name="B07" id="B07" class="inputbox" value="100" type="number">
					</td>
					<td name="C07" id="C07" class="">
					</td>
				</tr>
				<tr name="08" id="08" class="">
					<td name="A08" id="A08" class="inputlabel">
						&nbsp;INSULIN ON BOARD&nbsp;
					</td>
					<td name="B08" id="B08" class="">
						<input name="B08" id="B08" class="inputbox" value="0" type="number">
					</td>
					<td name="C08" id="C08" class="">
					</td>
				</tr>
				<tr name="09" id="09" class="">
					<td name="A09" id="A09" class="inputlabel">
						&nbsp;CARBOHYDRATES&nbsp;
					</td>
					<td name="B09" id="B09" class="">
						<input name="B09" id="B09" class="inputbox" value="0" type="number">
					</td>
					<td name="C09" id="C09" class="">
					</td>
				</tr>
				<tr name="10" id="10" class="">
					<td name="A10" id="A10" class="inputlabel">
						&nbsp;PROTEIN&nbsp;
					</td>
					<td name="B10" id="B10" class="">
						<input name="B10" id="B10" class="inputbox" value="0" type="number">
					</td>
					<td name="C10" id="C10" class="">
					</td>
				</tr>
				<tr name="11" id="11" class="">
					<td name="A11" id="A11" class="inputlabel">
						&nbsp;FAT&nbsp;
					</td>
					<td name="B11" id="B11" class="">
						<input name="B11" id="B11" class="inputbox" value="0" type="number">
					</td>
					<td name="C11" id="C11" class="">
					</td>
				</tr>
				<tr name="12" id="12" class="">
					<td name="A12" id="A12" class="outputlabel">
						&nbsp;CARBS FROM PROTEIN&nbsp;
					</td>
					<td name="B12" id="B12" class="">
						<input name="B12" id="B12" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C12" id="C12" class="">
					</td>
				</tr>
				<tr name="13" id="13" class="">
					<td name="A13" id="A13" class="outputlabel">
						&nbsp;CARBS FROM FAT&nbsp;
					</td>
					<td name="B13" id="B13" class="">
						<input name="B13" id="B13" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C13" id="C13" class="">
					</td>
				</tr>
				<tr name="14" id="14" class="">
					<td name="A14" id="A14" class="outputlabel">
						&nbsp;TOTAL CARBOHYDRATES&nbsp;
					</td>
					<td name="B14" id="B14" class="">
						<input name="B14" id="B14" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C14" id="C14" class="">
					</td>
				</tr>
				<tr name="15" id="15" class="">
					<td name="A15" id="A15" class="outputlabel">
						&nbsp;CARBS TO BOLUS NOW&nbsp;
					</td>
					<td name="B15" id="B15" class="">
						<input name="B15" id="B15" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C15" id="C15" class="">
					</td>
				</tr>
				<tr name="16" id="16" class="">
					<td name="A16" id="A16" class="outputlabel">
						&nbsp;CARBS FOR EXTENDED BOLUS&nbsp;
					</td>
					<td name="B16" id="B16" class="">
						<input name="B16" id="B16" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C16" id="C16" class="">
					</td>
				</tr>
				<tr name="17" id="17" class="">
					<td name="A17" id="A17" class="outputlabel">
						&nbsp;CORRECTION BOLUS&nbsp;
					</td>
					<td name="B17" id="B17" class="">
						<input name="B17" id="B17" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C17" id="C17" class="">
					</td>
				</tr>
				<tr name="18" id="18" class="">
					<td name="A18" id="A18" class="outputlabel">
						&nbsp;PROTEIN BOLUS&nbsp;
					</td>
					<td name="B18" id="B18" class="">
						<input name="B18" id="B18" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C18" id="C18" class="">
					</td>
				</tr>
				<tr name="19" id="19" class="">
					<td name="A19" id="A19" class="outputlabel">
						&nbsp;FAT BOLUS&nbsp;
					</td>
					<td name="B19" id="B19" class="">
						<input name="B19" id="B19" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C19" id="C19" class="">
					</td>
				</tr>
				<tr name="20" id="20" class="">
					<td name="A20" id="A20" class="outputlabel">
						&nbsp;CARB BOLUS&nbsp;
					</td>
					<td name="B20" id="B20" class="">
						<input name="B20" id="B20" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C20" id="C20" class="">
					</td>
				</tr>
				<tr name="21" id="21" class="">
					<td name="A21" id="A21" class="outputlabel">
						&nbsp;TOTAL BOLUS&nbsp;
					</td>
					<td name="B21" id="B21" class="">
						<input name="B21" id="B21" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C21" id="C21" class="">
					</td>
				</tr>
				<tr name="22" id="22" class="">
					<td name="A22" id="A22" class="outputlabel">
						&nbsp;UNITS TO DELIVER NOW&nbsp;
					</td>
					<td name="B22" id="B22" class="">
						<input name="B22" id="B22" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C22" id="C22" class="">
					</td>
				</tr>
				<tr name="23" id="23" class="">
					<td name="A23" id="A23" class="outputlabel">
						&nbsp;UNITS TO EXTEND&nbsp;
					</td>
					<td name="B23" id="B23" class="">
						<input name="B23" id="B23" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C23" id="C23" class="">
					</td>
				</tr>
				<tr name="24" id="24" class="">
					<td name="A24" id="A24" class="outputlabel">
						&nbsp;PERCENT TO DELIVER NOW&nbsp;
					</td>
					<td name="B24" id="B24" class="">
						<input name="B24" id="B24" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C24" id="C24" class="">
					</td>
				</tr>
				<tr name="25" id="25" class="">
					<td name="A25" id="A25" class="outputlabel">
						&nbsp;PERCENT TO EXTEND&nbsp;
					</td>
					<td name="B25" id="B25" class="">
						<input name="B25" id="B25" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C25" id="C25" class="">
					</td>
				</tr>
				<tr name="26" id="26" class="">
					<td name="A26" id="A26" class="outputlabel">
						&nbsp;MORE CARBS NEEDED&nbsp;
					</td>
					<td name="B26" id="B26" class="">
						<input name="B26" id="B26" class="outputbox" value="" type="number" readonly>
					</td>
					<td name="C26" id="C26" class="">
					</td>
				</tr>
			</table>
			<br>
			<input type="button" value="Calculate" name="CalculateButton" onclick="Calculate()">
		</form>
	</body>
</html>
P.S. I am by no means a professional and am aware that there might be better ways of doing this. I am still learning.

Last edited by ten3six; 11-03-2011 at 03:26 AM.. Reason: problem solved
ten3six is offline   Reply With Quote
Old 11-03-2011, 01:26 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ready to kick yourself?

Code:
    <input name="B12" id="B12" class="outputbox" value="" type="number" readonly>

and then

document.DCalcForm.B12.value=(Math.round(B12*100))/100 + ' g';
When you add the " g" to that value, it no longer fits the HTML5 specification for type="number"

Remove all your type's if you intend to keep putting " g" into them.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
ten3six (11-03-2011)
Old 11-03-2011, 03:22 AM   PM User | #3
ten3six
New Coder

 
Join Date: Jan 2011
Location: fort worth, tx
Posts: 11
Thanks: 2
Thanked 0 Times in 0 Posts
ten3six is an unknown quantity at this point
WOW!!!
That's the kind of simple thing that always get's me. The semi-colon doesn't like me at all. I hope the input box isn't joining semi-colon's team. That was it exactly. I didn't even add the text to those outputs until the last minute but it never occurred to me that I was trying to put letters into a number type box.

Thank you so much Old Pedant. I'll be kicking myself for a while after that.

Last edited by ten3six; 11-03-2011 at 03:25 AM..
ten3six is offline   Reply With Quote
Reply

Bookmarks

Tags
button, chrome, javascript, opera, safari

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:50 AM.


Advertisement
Log in to turn off these ads.