Archive for 19th September 2007

A JavaScript Temperature Conversion Program

Recently asked on Yahoo! Answers:

Java Question?

I was wondering, is it possible to see the source code from an applet that is on a website? Or is it once it is on the internet so well protected nobody can get it? It goes about this applet:
http://chemistry.about.com/library/weekly/bltempconvert.htm
I am trying to make such a converter myself but am a bit stuck so would want to see if the code from that applet can help me a bit further.. if someone could give a raw version of the code for such an applet it would be even better

Actually, the script this questioner referenced is not a Java applet, it’s a simple JavaScript converter program, like hundreds of others out there. But copying it would be somewhat difficult to do, and his request, sent in a follow-up e-mail to me, was pretty specific:

I really hope you can help me. I need an applet that looks like something as in the link I put in my Question. Is there any way to see the source code from that applet? If not if it’s not too much work could you show me what the code for an applet with 3 text fields with 3 buttons and behind them is? Then the text fields must represent Celcius Fahrenheit and Kelvin and when you click the button it gives you the temperature in the other 2 measurements and clear your input to 0.

Again, it’s not an applet. And it would be infinitely problematic, not to mention counterproductive, to set as 0 the input the person entered, while trying to compute the new values.

So, I modified this request: Our JavaScript will compute the other two temperatures from any temperature we enter. But we’re not going to use a button to submit the request; we’re going to use the onchange event for the textboxes to trigger our function. And we’re going to set the background color for the computed values to be pink, so we know what we entered and what was computed by the script.

Continue reading ‘A JavaScript Temperature Conversion Program’ »