Reputation: 8346
I have below JavaScript Code. It not getting called when page is loaded. Even Alert is not displaying; moment.min.js is placed in same folder..
<script type='text/javascript' src="moment.min.js">
alert("Testing Hello...")
var mysql_date = '2013-01-25 10:00:00';
var date = moment(mysql_date , 'YYYY-MM-DD HH:mm:ss'); // new moment.js object.
// To display the date in a different format use:
var date_format1 = date.format('MMM, Do'); // Format here would be Jan, 25th
var date_format2 = date.format('MMMM, Do, YYYY'); // January, 25th, 2013
alert(date_format1);
alert(date_format2);
console.log(date_format1, date_format2);
</script>
Please let me know why this script is not loaded when page is loaded
Upvotes: 0
Views: 115
Reputation: 585
For the calling the JavaScript on page and include the JavaScript file below is solution
<script type='text/javascript' src="moment.min.js"> </script>
<script type='text/javascript'>
window.onload=function() {
alert("Testing Hello...")
var mysql_date = '2013-01-25 10:00:00';
var date = moment(mysql_date , 'YYYY-MM-DD HH:mm:ss'); // new moment.js object.
// To display the date in a different format use:
var date_format1 = date.format('MMM, Do'); // Format here would be Jan, 25th
var date_format2 = date.format('MMMM, Do, YYYY'); // January, 25th, 2013
alert(date_format1);
alert(date_format2);
console.log(date_format1, date_format2);
};
</script>
Upvotes: 3
Reputation: 6625
Why include src
attribute when your are including javascript directly?
Add the code in moment.min.js
and just write <script src="moment.min.js"></script>
OR
<script src='moment.min.js'></script>
<script>
alert("Testing Hello...")
var mysql_date = '2013-01-25 10:00:00';
var date = moment(mysql_date , 'YYYY-MM-DD HH:mm:ss'); // new moment.js object.
// To display the date in a different format use:
var date_format1 = date.format('MMM, Do'); // Format here would be Jan, 25th
var date_format2 = date.format('MMMM, Do, YYYY'); // January, 25th, 2013
alert(date_format1);
alert(date_format2);
console.log(date_format1, date_format2);
</script>
Upvotes: 2
Reputation: 8156
either content or src
try this
<script type='text/javascript' src="moment.min.js">
</script>
<script>
alert("Testing Hello...")
var mysql_date = '2013-01-25 10:00:00';
var date = moment(mysql_date , 'YYYY-MM-DD HH:mm:ss'); // new moment.js object.
// To display the date in a different format use:
var date_format1 = date.format('MMM, Do'); // Format here would be Jan, 25th
var date_format2 = date.format('MMMM, Do, YYYY'); // January, 25th, 2013
alert(date_format1);
alert(date_format2);
console.log(date_format1, date_format2);
</script>
Upvotes: 4