-3

The most logical way that came to my mind was doing

var example2 = "Jake"
if (<%=Session["example1"]%> == example2){
   Code
}

However i get this error: The value of what is written inside that session variable is "undefined"... so if it were a name(Bob) that's inside that session variable, it would say Bob is undefined

Anyone got a solution for me?

Yuval Roth
  • 75
  • 1
  • 9
  • Please post your **rendered** HTML, verbatim, as an example. – Dai Mar 31 '15 at 18:46
  • Why would i need to post anything about html? my question didn't even concern html, @dai – Yuval Roth Mar 31 '15 at 19:02
  • And i don't understand why people downvoted my question! it's a perfectly reasonable question and i supplied all information needed! – Yuval Roth Mar 31 '15 at 19:03
  • By "rendered HTML" I mean the rendered document as sent from the server (i.e. where the `<%= %>` was replaced with the actual output) so we could see what the browser was actually receiving and running. I said HTML because the output is part of a HTML document. – Dai Mar 31 '15 at 19:19
  • @Dai, That's just irrelevant information. I got my answer without it. – Yuval Roth Mar 31 '15 at 19:33
  • Yuval, it is not irrelevant information. We need to know exactly what the browser was parsing which caused it to give us the "undefined" runtime error. We could infer that it was missing single-quotes (for Steve Drake's answer), but what if it was numeric or JSON data? – Dai Mar 31 '15 at 19:44
  • JSON, @Dai. The document that replaced that variable's value was the login form... is that what you meant for "rendered HTML"? – Yuval Roth Apr 01 '15 at 05:30

1 Answers1

1

you need ' ' around it, eg

var example2 = "Jake"
if ('<%=Session["example1"]%>' === example2){
   Code
}

Or.. " " if that's your thing :)

Also, note the === vs ==

Steve Drake
  • 1,968
  • 2
  • 19
  • 41