Click to See Complete Forum and Search --> : get Javascript variable from ASP


Danbabe
02-15-2009, 05:19 PM
Hi folks,

I have a script that displays a calendar nicely on the asp web page. Is there a way of getting one of the javascript variables from within the ASP code?

This is the script code I have:

<script type="text/javascript">
function buildCal(m, y, cM, cH, cDW, cD, brdr){
var mn=['January','February','March','April','May','June','July','August','September','October','November',' December'];
var dim=[31,0,31,30,31,30,31,31,30,31,30,31];

var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st

var todaydate=new Date() //DD added
var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added

dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr align="center">';
t+='<td colspan="7" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';
for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"SMTWTFS".substr(s,1)+'</td>';
t+='</tr><tr align="center">';
for(i=1;i<=42;i++){
var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';
if (x==scanfortoday) //DD added
x='<span id="today"><% If s = javascript:x; Then %><a href="default.asp"><% End If %>'+x+'<% If s = javascript:x; Then %></a><% End If %></span>' //This td is shown for todays date else
t+='<td class="'+cD+'">'+x+'</td>'; //This td is shown if not todays date
if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
}
return t+='</tr></table></div>';
}
</script>

As you can see from the bold part of the script, I am trying to get the javascript variable of x into the ASP script.

Does anyone know how to do this please? This is driving me mad...

Many thanks

D

yamaharuss
02-15-2009, 08:26 PM
Since Javascript is a client side language and ASP is server side, you can read ASP into Javascript but not the other way around.