Jump to content


Photo

Math with no javascript. I don't understand it.


  • Please log in to reply
5 replies to this topic

#1 crmamx

crmamx

    Advanced Member

  • Members
  • PipPipPip
  • 423 posts
  • LocationAlabama

Posted 15 February 2013 - 11:19 AM

<html>
<head>
<style>
#table.my-table{
border-color: #FFCC00 #FFCC00 #FFCC00 #FFCC00; <!-- #BFBFBF #5A5A5A #5A5A5A #BFBFBF; -->
bgcolor: #FFCC00;
border-style: solid;
border-width: 10px;
text-align: left;
border-collapse: separate;
border-spacing: 2px;	
}
table.my-table tr{		
}
.my-table td{			
padding:2px 7px;		
border:1px solid;
border-color:#5A5A5A #BFBFBF #BFBFBF #5A5A5A ;
}
</style>
</head>
<body>
<FORM>
<center>
<table BORDER=4 BGCOLOR="#bfe3fe" >
	 <tr>
	 <td ALIGN=CENTER VALIGN=CENTER COLSPAN="7"><center><h2>Temperature Conversion Calculator</h2></center>
	 </td>
	 </tr>
	 <tr>
	 <td ALIGN=CENTER>Fahrenheit</td>
	 <td ALIGN=CENTER>Celsius</td>
	 <td ALIGN=CENTER>Kelvin</td>
	 <td><center><INPUT TYPE="Reset" NAME="Reset" VALUE="Reset"></center></td>
	 </tr>
	 <tr>
	 <td><center><INPUT TYPE="text" NAME="F" VALUE="" SIZE="6" MAXLENGTH="6" onchange="eval('C.value = ' + this.form.C_expr.value);eval('K.value = ' + this.form.K_expr.value)">
				 <INPUT TYPE="hidden" NAME="F_expr" VALUE="(Math.round(((212-32)/100 * C.value + 32)*100))/100;">
				 <INPUT TYPE="hidden" NAME="F_expr2" VALUE="(Math.round(((212-32)/100 *(K.value - 273) + 32)*100))/100; "></center></td>
	 <td><center><INPUT TYPE="text" NAME="C" VALUE="" SIZE="6" MAXLENGTH="6" onchange="eval('F.value = ' + this.form.F_expr.value);eval('K.value = ' + this.form.K_expr.value)">
				 <INPUT TYPE="hidden" NAME="C_expr" VALUE="(Math.round((100/(212-32) * (F.value - 32))*100))/100"> <INPUT TYPE="hidden" NAME="C_expr2" VALUE="(Math.round(K.value - 273))"></center></td>
	 <td><center><INPUT TYPE="text" NAME="K" VALUE="" SIZE="6" MAXLENGTH="6" onchange="eval('F.value = ' + this.form.F_expr2.value);eval('C.value = ' + this.form.C_expr2.value)">
				 <INPUT TYPE="hidden" NAME="K_expr" VALUE="(Math.round((100/(212-32) * (F.value - 32))*100))/100 + 273"></center></td>
	 <td><center><INPUT TYPE="button" NAME="Reset" VALUE="Calculate"></center></td>
	 </tr>
</table>
</center>
</FORM>
</body>
</html>
I was looking for a program to do length, volume, weight and temperature conversions for my web site. I found the first 3 written in Javascript. I tried to modify it to include temperature with no success. Then I discovered one for temperature and modified the look to match what I already had.

But I have never seen computations done with html alone. I cannot find an explanation anywhere. Everything I can find says “onchange designates a Javascript to run…”

Can you point me to an explanation of :

onchange="eval('C.value = ' + this.form.C_expr.value);eval('K.value = ' + this.form.K_expr.value)">

and

VALUE="(Math.round(((212-32)/100 * C.value + 32)*100))/100;">

I understand the math. But I can’t find “eval, this form, C expr.value” used with onchange. And I can’t find “Math.round” used with VALUE.

Edited by crmamx, 15 February 2013 - 11:29 AM.

If at first you do not succeed, QUIT, because it becomes too aggravating.

Why is it I don't understand everything I know?

http://southalabamarc.com

#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 15 February 2013 - 11:23 AM

But I have never seen computations done with html alone. I cannot find an explanation anywhere. Everything I can find says “onchange designates a Javascript to run…”

Because it can't. HTML is purely markup. It cannot do math.

Can you point me to an explanation of :

onchange="eval('C.value = ' + this.form.C_expr.value);eval('K.value = ' + this.form.K_expr.value)">

and

VALUE="(Math.round(((212-32)/100 * C.value + 32)*100))/100;">

I understand the math. But I can’t find “eval, this form, C expr.value” used with onchange. And I can’t find “Math.round” used with VALUE.


What are you confused about? The functions you use in an onchange are irrelevant to how they work.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 crmamx

crmamx

    Advanced Member

  • Members
  • PipPipPip
  • 423 posts
  • LocationAlabama

Posted 15 February 2013 - 11:51 AM

I am only familiar with javascript calling a function and I have not defined a function. So are you saying that the code is executing javascript?

What about "Value=(Math.round..........."? Is this also javascript?
If at first you do not succeed, QUIT, because it becomes too aggravating.

Why is it I don't understand everything I know?

http://southalabamarc.com

#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 15 February 2013 - 11:54 AM

Everything inside the onchange attribute is javascript.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#5 crmamx

crmamx

    Advanced Member

  • Members
  • PipPipPip
  • 423 posts
  • LocationAlabama

Posted 15 February 2013 - 12:43 PM

Many thanks. I now have a totally new outlook on life........well, almost.

I can usually get the job done although I certainly am not an advanced coder. I have called functions but never realized you could execute javascript without being inside <script></script>.
If at first you do not succeed, QUIT, because it becomes too aggravating.

Why is it I don't understand everything I know?

http://southalabamarc.com

#6 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 15 February 2013 - 01:03 PM

You really SHOULDN'T but it's possible.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com