Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1390 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Help with JavaScript

Thread title: Help with JavaScript
Reply    
    Thread tools Search this thread Display Modes  
01-02-2010, 05:47 AM
#1
AndrewIGO is offline AndrewIGO
Status: Junior Member
Join date: Feb 2006
Location:
Expertise:
Software:
 
Posts: 58
iTrader: 4 / 100%
 

AndrewIGO is on a distinguished road

  Old  Help with JavaScript

So I was given this code in a class I'm taken, and it's directly from the book. But it doesn't show up. It's suppose to be in between two bars at the top of a web page. Can anyone take a look and see why this code isn't working?


<tr>
<td>
<hr size="5" />
<p style="margin-left:10%">
<script type="text/javascript">
<!--Hide from old browsers
var today = new Date();
var dayofweek = today.toLocaleString();
var dayLocate = dayofweek.indexOf(" ");
var weekDay = dayofweek.substring(0, dayLocate);
var newDay = dayofweek.substring(dayLocate);
var dateLocate = newDay.indexOf(" ");
var monthDate = newDay.substring(0, dateLocate+1);
var yearLocate = dayofweek.indexOf("2010");
var year = dayofweek.substr(yearLocate, 4);

var springDate = new Date("March 21, 2010");
var daysToGo = springDate.getTime()-today.getTime();
var daysToSpring = Math.ceil(daysToGo/(1000*60*60*24));

document.write("<p style="margin-left:10%; font-family:Arial, sans-serif; font-weight:bold; font-size:14">Today is "+weekDay+" "+monthDay+" "+year+", that leaves only "+ daysToSpring +" days until the start of spring.")
document.write("<br />Spring is the time to prepare your landscape for new growth of flowers and lawns. ")
document.write("<br />Call us now at (221) 555-9100 for a free consultation and free eestimate.</p>")

//-->
</script>
</p>
<hr size="5" /> </td>
</tr>

Reply With Quote
01-02-2010, 07:38 AM
#2
hjalmar is offline hjalmar
Status: Senior Member
Join date: Nov 2004
Location: Sweden
Expertise:
Software:
 
Posts: 857
iTrader: 11 / 100%
 

hjalmar is an unknown quantity at this point

  Old

HTML Code:
	<script type="text/javascript">
	<!--Hide from old browsers
	var today = new Date();
	var dayofweek = today.toLocaleString();
	var dayLocate = dayofweek.indexOf(" ");
	var weekDay = dayofweek.substring(0, dayLocate);
	var newDay = dayofweek.substring(dayLocate);
	var dateLocate = newDay.indexOf(" ");
	var monthDate = newDay.substring(0, dateLocate+1);
	var yearLocate = dayofweek.indexOf("2010");
	var year = dayofweek.substr(yearLocate, 4);

	var springDate = new Date("March 21, 2010");
	var daysToGo = springDate.getTime()-today.getTime();
	var daysToSpring = Math.ceil(daysToGo/(1000*60*60*24));

	document.write("<p style=\"margin-left:10%; font-family:Arial, sans-serif; font-weight:bold; font-size:14\">Today is "+weekDay+" "+monthDate+" "+year+", that leaves only "+ daysToSpring +" days until the start of spring.")
	document.write("<br />Spring is the time to prepare your landscape for new growth of flowers and lawns. ")
	document.write("<br />Call us now at (221) 555-9100 for a free consultation and free eestimate.</p>")

	//-->
	</script>
You need to escape " and you had a typo... monthDay? monthDate?

Reply With Quote
01-02-2010, 08:01 AM
#3
AndrewIGO is offline AndrewIGO
Status: Junior Member
Join date: Feb 2006
Location:
Expertise:
Software:
 
Posts: 58
iTrader: 4 / 100%
 

AndrewIGO is on a distinguished road

  Old

Ah, thanks.

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed