1

here is my function which is put into its own file(Javascript/submitDate.js):

document.onload = function(){
  function submitDate(){
  var time = new Date();
  var nowDate =time.toISOString().slice(0,-14);
  document.getElementById("dateShow").value=nowDate;
}
submitDate();   
}();

This ran fine before I joined the page with my index.(When I put all my javascript and page layout into one file)

Here is the page(projectMain.html) of the code:

<html>
  <div id="container">
   <header>
    <h3>Entries close on the 10th of March</h3>


   </header>
   <section>
     <aside onload="submitDate();">
        Last submitted: 
        </br>
        <input type="date" id="dateShow" readonly>      
     </aside>
   </section>

No errors pop up and it just shows the date layout box as: mm/dd/yyyy

EDIT: The folder has a capital J.

Edit 2.0: Link to what is shown. Underneath the "last submitted" is the date function that is not working. : http://prntscr.com/60ie8k

Edit 3.0: Here is my Index:

<html>
<head>
    <title>Sample Template</title>
    <link rel="stylesheet" language="text/css" href="CSS/stylesheet.css"/>
    <script language="javascript" src="Javascript/AJAX.js"></script>
</head>
<body onload="javascript:changePage('home');">
<h1>Little Big Planet</h1>
<div class="menu">
    <a onclick="javascript:changePage('home');">Home</a>
    <a onclick="javascript:changePage('powerups');">Power Ups</a>
    <a onclick="javascript:changePage('bots');">Sackbots</a>
    <a onclick="javascript:changePage('costumes');">Costumes</a>
    <a onclick="javascript:changePage('projectMain');">Form</a>
</div>
<br />
<div id="content">
</div>
<script type="text/javascript" src="Javascript/submitDate.js"></script>
</body>
</html>

3 Answers 3

3

The aside element doesn't have an onload attribute (or load event). Only elements that load external content (e.g. <img>) and the document itself (where the attribute lives on the <body> element) do.

Use a <script> element instead.

 <aside>
    Last submitted: 
    </br>
    <input type="date" id="dateShow" readonly>      
 </aside>
 <script>
     submitDate();
 </script>

Additionally, you say that the file lives at "javascript/submitDate.js" but you are loading src="Javascript/submitDate.js". The function won't be available to call if you are using a case-sensitive file system (as the URL will 404).

Sign up to request clarification or add additional context in comments.

1 Comment

Tried this as well as everybody else's tips. Must be some other type of error.
0

You have a capitol 'j' in JavaScript in your HTML.

<script type="text/javascript" src="Javascript/submitDate.js"></script>

3 Comments

because his folder has a capital J
but he say it was in javascript/submitDate.js. Lowercase 'J'.
You're correct, didn't see that at the top. well spotted
0

Try loading the js when the document is loaded

JS file:

    document.onload = function(){
    function submitDate(){
    var time = new Date();
    var nowDate =time.toISOString().slice(0,-14);
    document.getElementById("dateShow").value=nowDate;
    }
    submitDate();   
}();

The aside in your html

   <aside>
    Last submitted: 
    </br>
    <input type="date" id="dateShow" readonly>      
 </aside>

Link to js file in the bottom of your body

<script type="text/javascript" src="pathtojsfile"></script>

Here is a working Fiddle

5 Comments

Tried this, still no change.
Where do I put the: <script type="text/javascript" src="pathtojsfile"></script>
just before the </body> tag in your html. change pathtojsfile to the path where your js file is located. Check the console window in your browser to check for errors when loading the script
I have been using AJAX javascript file. WIll this make any difference?
can you edit the post with the scriptfile you are using?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.