Solved

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

Posted on 2014-09-16
8
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 33

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 33

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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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
 
LVL 33

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 33

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

627 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