Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:

Thread Tools   Display Modes
  View First Unread
Old 04-01-2012, 11:00 AM
Soldier (Level 11)
Join Date: Oct 2008
Location: Cincinnati, OH
Posts: 135
iTrader: (0)
webmast3r is an unknown quantity at this point
Temperature Calc Help

Been awhile since I've done JavaScript so bear with me. I'm trying to make a Temperature calculator that disables the textbox (which displays the result) onclick of a radio button. The user inputs a number in the other textbox(rounds decimals to the nearest integer) and does the selected conversion on button click. I'm having trouble disabling the textbox onclick of the radio button, and getting the calculation setup. If no buttons are clicked, an alert message appears. Any help would be greatly appreciated.

<title>Temperature Converter</title>
<script type="text/javascript">
function calculate() {
var btn1 = document.form.btn1[i].checked;
var btn2 = document.form.btn2[i].checked;
var faren = document.getElementsByName('farenheit').value
var result = 0;

if (btn1 == true) {
	document.form.celcius.disabled = true;
	result = (faren-32) * (5/9);
	document.form.celcius.value = result;
else {
	alert("You didn't select a button.");

if (btn2 == true) {
	document.form.farenheit.disabled = true;
else {
	alert("You didn't select a button.");
<h2>Convert Temperature</h2>
<form action="mailto:skalamanga89@yahoo.com" method="post" name="form">
<input type="radio" name="btn1"/>From Farenheit to Celcius<br/>
<input type="radio" name="btn2"/>From Celcius to Farenheit<br/><br/>

Degrees Farenheit:<input type="text" name="farenheit"/><br/>
Degrees Celcius:<input type="text" name="celcius"/><br/><br/>

<input type="submit" name="convert" value="Convert" onclick="calculate()"/>
Associate of Applied Business in Webpage Management Technology
University of Cincinnati
E-Portfolio Web Site - http://brandone-portfolio.net84.net/index.html

webmast3r is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 04-01-2012, 11:28 AM
Big Tuna
blackpepper's Avatar
Join Date: Jul 2005
Posts: 1,636
iTrader: (0)
blackpepper will become famous soon enoughblackpepper will become famous soon enough
try something like this

function disable(field){
	document.getElementById(field).readOnly = true; }
and then call this function onClick of the radio button
"All I know is that I know nothing"
blackpepper is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump


All times are GMT -5. The time now is 06:42 PM.


Mascot team created by Drawshop.com | Web Hosting

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.