xdbuix Posted September 20, 2013 Share Posted September 20, 2013 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!Danhtml- <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Average Temperatures</title> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![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; Link to comment Share on other sites More sharing options...
Larry Posted September 20, 2013 Share Posted September 20, 2013 I'm sorry, but it's not clear what exactly you want me to do. Is there a specific question or problem? Link to comment Share on other sites More sharing options...
Recommended Posts