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!

How to combine JS and ASP ?

Status
Not open for further replies.

leifoet

Technical User
Jan 31, 2016
206
BE
I am trying to check if a day (of a date) is odd or even - with the code below.
If I use the variable var_day instead of a number, nothing happens.
Look for a solution
Thanks.

Code:
<%
var_day = Day(date())
%>

<p id="demo"></p>
<script>
{
 var d = "";
 d = d + Number.isInteger(var_day); 
document.getElementById("demo").innerHTML = d;
}
</script>
 

var_day in your example exists on the server. JavaScript lives on the client. You'll have to inject your server value into a JavaScript variable in order for the client to see it.

<p id="demo"></p>
<script>
{
var var_day = '<%=Day(date())%>';
var d = "";
d = d + Number.isInteger(var_day);
document.getElementById("demo").innerHTML = d;
}
</script>


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Code:
<p id="demo"></p>
<script>
{
var var_day = '<%=Day(date())%>';
var d = "";
d = d + Number.isInteger(var_day);
document.getElementById("demo").innerHTML = d;
}
</script>

The result of this code is 'false' => should be 'true' ?
 
Hi

leifoet said:
The result of this code is 'false' => should be 'true' ?
Well, there are single quotes ( ' ) in the JavaScript code around whatever the ASP would ever produce :
Code:
[b]var[/b] var_day = [green][i]'<%=Day(date())%>'[/i][/green][teal];[/teal]

[gray]  ||
  \/[/gray]

[b]var[/b] var_day = [green][i]'28'[/i][/green][teal];[/teal]

Ask your browser in it's console, how it sees such value :
Code:
[gray]13:20:39.348[/gray] >> [purple]Number[/purple].[green]isInteger[/green]([navy]28[/navy])
[gray]13:20:39.366[/gray] [gray]<-[/gray] [green]true[/green]
[gray]13:20:42.246[/gray] >> [purple]Number[/purple].[green]isInteger[/green]([navy]'28'[/navy])
[gray]13:20:42.261[/gray] [gray]<-[/gray] [green]false[/green]

Feherke.
feherke.github.io
 
Thanks feherke for the solution: without quotes.
BTW: how could I test that in the browser - a little explanation?
 
Hi

I mean your browser's console from the developer tools. The one you can access like these
[pre]┌─────────┬──────────────────────────────┬──────────────┬─────────────┐
│ Browser │ Command │ Hotkey to │ Alternative │
│ │ │ the command │ hotkey │
├─────────┼──────────────────────────────┼──────────────┼─────────────┤
│ Firefox │ Web Developer | Toggle Tools │ Ctrl-Shift-I │ F12 │
│ Chrome │ More tools | Developer tools │ Ctrl-Shift-I │ F12 │
│ Opera │ │ Ctrl-Shift-I │ │
│ Vivaldi │ Developer Tools │ Ctrl-Shift-I │ │
└─────────┴──────────────────────────────┴──────────────┴─────────────┘[/pre]
Then in the tools panel select the Console tab.

You type the JavaScript expression you are working on ( the part after the "[tt]>>[/tt]" in my previous post ) and after pressing Enter is evaluated ( the part after the "[tt][gray]<-[/gray][/tt]" in my previous post ). Such JavaScript code gets evaluated in the current page's context, so you can access and even manipulate the document, to better understand what happens.

Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top