Solved

Value not being displayed on page <%=todayStr()%>

Posted on 2014-09-16
8
224 Views
Last Modified: 2014-09-16
I am using ASP/JavaScript

I have the following script inside the page:

 <% function todayStr() {
var today=new Date()
return today.getMonth()+1+"/"+today.getDate()+"/"+(today.getYear())
}
%>

and in the HTML I have this:

date:  <%=todayStr()%>

But no value is displayed. Why is this ?
0
Comment
Question by:amucinobluedot
  • 4
  • 3
8 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 400 total points
ID: 40325427
are you using server side javascript?
0
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 100 total points
ID: 40325433
You need to use the ampersand (&) to concatenate strings in ASP. Change the pluses (+) to ampersands (&) and see if that makes a difference.

So, this line
return today.getMonth()+1+"/"+today.getDate()+"/"+(today.getYear())

Open in new window


should look like:
return (today.getMonth()+1) & "/" & today.getDate() & "/" & (today.getYear())

Open in new window

0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 400 total points
ID: 40325442
if you want to use server side javascript, you need to specify that at the top of your page, like so:

<%@language="javascript" %>

<% function todayStr() {
var today=new Date()
return today.getMonth()+1+"/"+today.getDate()+"/"+(today.getYear())
}
%>


date:  <%=todayStr()%>

Open in new window


stick this code in a page and it it displays todays date
0
 

Author Comment

by:amucinobluedot
ID: 40325446
Yes. Top of page reads:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 400 total points
ID: 40325448
if you want to use server side vbscript, which is the standard, you want to change your function to something like:

<%@language="vbscript" %>

<% function todayStr() {
var today = now()
todayString = FormatDateTime( today, 2 )
end function
%>


date:  <%=todayStr()%>

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 40325452
Big Monty:   I already have that but the value still not being displayed on the page. :$  
Also, this value is used to be inserted in the database in a hidden field and there the value is also null
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 400 total points
ID: 40325466
Big Monty:   I already have that but the value still not being displayed on the page. :$  

you have a dollar sign there but are expecting a date....are you sure you're looking in the right spot?

without seeing more code, it's going to be difficult to diagnose.

the code you posted is correct in and of itself, my guess is there's something else going on in your page. if you want to post the entire page worth of code, i can have a look
0
 

Author Comment

by:amucinobluedot
ID: 40325511
There is something else on the page causing this issue because I used the initial posted script in my page and it worked just fine:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
 <% function todayStr() {
 var today=new Date()
 return today.getMonth()+1+"/"+today.getDate()+"/"+(today.getYear())
 }
 %>
</head>

<body>
date: <%=todayStr()%>
</body>
</html>
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to dynamically set the form action using jQuery.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now