×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to combine JS and ASP ?

How to combine JS and ASP ?

How to combine JS and ASP ?

(OP)
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> 

RE: How to combine JS and ASP ?


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

RE: How to combine JS and ASP ?

(OP)

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' ?

RE: How to combine JS and ASP ?

Hi

Quote (leifoet)

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 --> (fragment)

var var_day = '<%=Day(date())%>';

  ||
  \/

var var_day = '28'; 

Ask your browser in it's console, how it sees such value :

CODE --> Console

13:20:39.348 >> Number.isInteger(28)
13:20:39.366 <- true
13:20:42.246 >> Number.isInteger('28')
13:20:42.261 <- false 

Feherke.
feherke.github.io

RE: How to combine JS and ASP ?

(OP)
Thanks feherke for the solution: without quotes.
BTW: how could I test that in the browser - a little explanation?

RE: How to combine JS and ASP ?

Hi

I mean your browser's console from the developer tools. The one you can access like these
┌─────────┬──────────────────────────────┬──────────────┬─────────────┐
│ 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 │             │
└─────────┴──────────────────────────────┴──────────────┴─────────────┘ 
Then in the tools panel select the Console tab.

You type the JavaScript expression you are working on ( the part after the ">>" in my previous post ) and after pressing Enter is evaluated ( the part after the "<-" 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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close