Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
xdbuix

Chapter 6 Assignment

Recommended Posts

Hey Larry!

I've been working on my assignment and I've hit a roadblock. I was hoping you can take a look for me. I'm able to get the output out, however there are a few kinks i'm running into. I'm trying to sum up my output temperature numbers. Also the dates are suppose to go down 1 day from today each time you submit.

Thanks Larry!
Dan

html-

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Average Temperatures</title>
    <!--[if lt IE 9]>
    <![endif]-->
    <link rel="stylesheet" href="css/form.css">
</head>
<body>
    <!-- employee.html -->
<form action="#" method="post" id="theForm">
   <fieldset><legend>Average Low Temperatures and high Temperatures</legend>
       <div><label for="lowtemp">Low Temp</label><input type="text" name="lowtemp" id="lowtemp" required></div>
       <div><label for="hightemp">High Temp</label><input type="text" name="hightemp" id="hightemp" required></div>
     
       <input type="submit" value="Add the Temperatures" id="submit">
   </fieldset>
   <div id="output"></div>
</form>
    <script src="js/temps3.js"></script>
</body>
</html>

javascript-
// tasks.js
// This script creates an array using form data.
 
// Need to create an array of low temperatures:
var lowtemps = [];
 
// Function called when the form is submitted.
// Function creates a new object.
function process() {
    'use strict';
 
    // Get form references:
    var lowtemp = (document.getElementById('lowtemp'));
 
 
    // Reference to where the output goes:
    var output = document.getElementById('output');
 
    // Create the ouptut as HTML:
var message = ' ';
var today=new Date();
var curDay=' ';
 
if (!isNaN(lowtemp.value)) {
 
//add the temps to the array;
lowtemps.push(lowtemp.value);
 
//Update the page
message = '<table class="left"><th>Date</th><th>Low Temperatures</th>';
curDay=today.toLocaleDateString();
for (var i=0, count=lowtemps.length; i < count; i++)
{
message+='<tr><td class="right">' + curDay + '</td> <td class="right">' + lowtemps + '</td></tr>'; //It is displaying the current day now but that needs to change each day. So re-examine the curDay variable..I actually do not use toLocaleDateString. I use a combination of getMonth() getDate() and getYear() and you can add or subtract 1 from each of those as needed.
}
}
else
{ // The low temp is invalid!
message = 'Please enter valid low temperatures.';
}
output.innerHTML = message;
// End of lowtemps IF.
 
//Return false to prevent submission:
return false;
 
} // End of process() function
  
// Initial setup:
function init() {
    'use strict';
    document.getElementById('theForm').onsubmit = process;
} // End of init() function.
window.onload = init;
 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...