?
Solved

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

Posted on 2014-09-16
8
Medium Priority
?
232 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 1600 total points
ID: 40325427
are you using server side javascript?
0
 
LVL 27

Assisted Solution

by:Shaun Kline
Shaun Kline earned 400 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 1600 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

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 1600 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 1600 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This video teaches users how to migrate an existing Wordpress website to a new domain.

719 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