Solved

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

Posted on 2014-09-16
8
223 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
Comment Utility
are you using server side javascript?
0
 
LVL 25

Assisted Solution

by:Shaun Kline
Shaun Kline earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

743 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

17 Experts available now in Live!

Get 1:1 Help Now