Solved

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

Posted on 2014-09-16
8
228 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

739 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