Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS - Javascript output doesn't display 1

Status
Not open for further replies.

ppetree

Programmer
Mar 3, 2007
60
US
I have a header file called (*gasp*) header.js which gets included in ALL my pages (asp and plain htm).

This header file checks some variables and if appropriate it then outputs the needed html strings.

Here are the variables"
Code:
var showdate	= "yes"		// SHOW DATE AT THE TOP
var showsearch	= "yes"		// SHOW THE SEARCH FORM
var searchtext	= "Search:"	// TEXT FOR SEARCH FORM
var showlogin	= "yes"		// SHOW THE LOGGED IN USERS NAME
var logintext	= "Logged in as: "

I'll skip the showsearch code because its too long but next is the showdate code and this works just fine!
Code:
// START DATE SCRIPT
if (showdate == "yes") {
  document.write('<div id="date-location">');
  var d=new Date()
  var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
  var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
  document.write("<span class=\"date-font\"><nobr>" + weekday[d.getDay()] + " ")
  document.write(d.getDate() + ". ")
  document.write(monthname[d.getMonth()] + " ")
  document.write(d.getFullYear())
  document.write("</nobr><br></span>")
  document.write('</div>');
}

Next is the code to show the users name if they are logged in:

Code:
// START LOGIN SCRIPT
if(showlogin == "yes") {
  var strFirst = Session("first");
  var strLast = Session("last");
  document.write('<div id="login-location">');
  if(strFirst != "")
  {
    document.write('<span class=\"date-font\"><nobr>' );
    document.write(logintext + strFirst +" " +strLast);
    document.write('</nobr><br></span>');
  }
  document.write('</div>');
}

Lastly here are the .css definitions for both the date and the login:
Code:
.date-font  { color: #000000; font: 10px verdana, arial, sans-serif; font-weight: normal }

#date-location 	{ left: 5px; POSITION: absolute; TOP: 4px }


.login-font  { color: #339900; font: 10px verdana, arial, sans-serif; font-weight: normal }

#login-location  { left: 250px; POSITION: absolute; TOP: 4px }

For the life of me I can't figure out why the date will display and the logged in user name will not! (And yes, I am logged in when I test this! <g>)

Anyone have any ideas?

Thanks,

Phil
 
Code:
var strFirst = [!]"<%=Session('first')%>"[/!];
var strLast = [!]"<%=Session('last')"[/!];

Session variables are ASP server side, not client side as you are trying to make them.

Assuming those session variables really do contain something, what I wrote above should work.




[monkey][snake] <.
 
Doh!

Good catch!

(but your code wouldn't work in html pages, they'd all have to be converted to .asp)

Thanks!

Phil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top