-
October 9th, 2009, 03:39 PM #1Junior Member
- Join Date
- Oct 2009
- Posts
- 2
Writing to an Input Text from a Function
Can't seem to pass the mpg value to the milespergallon input text box. Any help on how to get this value in the box from the function. This is an online class and the instructor rarely replies to our email questions.
Thanks in advance.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="js_styles.css" type="text/css" />
<title>Miles Per Gallon Calculator</title>
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-1" />
<script type="text/javascript">
/* <![CDATA[ */
function calcMPG(startingMiles, endingMiles, gallons) {
var startingMiles = parseInt(document.getElementById('startingmiles'). value);
var endingMiles = parseInt(document.getElementById('endingmiles').va lue);
var gallons = parseInt(document.getElementById('gallonsused').va lue);
var mpg = (endingMiles - startingMiles) / gallons;
?/* just writes to a new page not the mpg input text box*/
document.write(mpg.milespergallon = mpg);
}
/* ]]> */
</script>
</head>
<body>
<h1>Miles Per Gallon Calculator</h1>
<form name="mpg" action="">
<p><strong>Starting Mileage:</strong></p>
<p><input type="text" id="startingmiles" name="startingmiles" value=0 onchange="calcMPG(this)" /></p>
<p><strong>Ending Mileage:</strong></p>
<p><input type="text" id="endingmiles" name="endingmiles" value=0 onchange="calcMPG(this)" /></p>
<p><strong>Gallons Used:</strong></p>
<p><input type="text" id="gallonsused" name="gallonsused" value=0 onchange="calcMPG(this)" /></p>
<p><strong>Miles Per Gallon:</strong></p>
<p><input type="text" name="milespergallon" value=0 readonly="readonly" /></p>
</form>
<script type="text/javascript">
/* <![CDATA[ */
calcMPG();
/* ]]> */
</script>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10-blue"
alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
</body>
</html>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
LARGE TEXT > small text ?
By ClubMed in forum General Tech DiscussionReplies: 0Last Post: April 12th, 2005, 07:29 AM -
Toshiba laptop function keys won't function
By sparkle in forum Technical SupportReplies: 2Last Post: September 25th, 2004, 03:20 PM -
writing C
By butch81385 in forum Webmastering and ProgrammingReplies: 5Last Post: September 2nd, 2004, 11:07 AM -
changing text in text boxes
By Carl-cox- in forum Webmastering and ProgrammingReplies: 3Last Post: March 20th, 2003, 02:57 PM -
BlindWrite not Writing
By JacobM5727 in forum Technical SupportReplies: 6Last Post: February 17th, 2002, 08:55 PM



LinkBack URL
About LinkBacks



Reply With Quote

After long wait here is some awesome releases of 2013.Have look and have a nice day. Watch The Great Gatsby Online Watch Pain & Gain Online Watch Iron Man 3 Online Watch Star Trek Into Darkness...
Watch Spring Breakers Online Here