SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    ASP inside Javascript

    Im trying to mix some ASP inside of some javascript with no luck. I was wondering if the 2 languages dont work together..Heres my code...

    <SCRIPT LANGUAGE="JavaScript">

    function load() {


    <%
    on error resume next
    set fso = createobject("scripting.filesystemobject")
    set act = fso.opentextfile(server.mappath("active.txt"))
    active = clng(act.readline)
    active = active + 1
    act.close
    Set act = fso.CreateTextFile(server.mappath("active.txt"),true)
    act.WriteLine(active)
    act.Close
    %>



    }


    function unload() {

    <%
    on error resume next
    set fso = createobject("scripting.filesystemobject")
    set act = fso.opentextfile(server.mappath("active.txt"))
    active = clng(act.readline)
    active = active - 1
    act.close
    Set act = fso.CreateTextFile(server.mappath("active.txt"),true)
    act.WriteLine(active)
    act.Close
    %>


    }

    </SCRIPT>


    <BODY onLoad="load()" onunload="unload()">

    basically Im just writing to a text file when they come or go. Pulling all sorts of errors, I know the code inside the {} works. Any suggestions??

  2. #2
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ASP is executed then inserted into the page. The javascript is executed once the pages has been served by the webserver, after it has been proccessed by ASP. So, the code you have will not work. It IS possible to dynamically write javascript commands with ASP but not in this fashion.

  3. #3
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That wasnt the answer I wanted to hear, but I had a feeling it wasnt going to work. Anyone have any suggestions on how I could do this a different way?

    What Im trying to do is as soon as the user comes to a page to add one to the text file, and when they leave I want it to subtract one from the text file...

  4. #4
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if this is going to be used for a "Number of users Logged In : #" jobbie, then why dont you just use the session/application variable.

    Kevins toot on this worked well for me?

    http://www.webmasterbase.com/article.php?pid=0&aid=472

  5. #5
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ***It IS possible to dynamically write javascript commands with ASP but not in this fashion.


    Does anyone know how it is possible to write ASP code within a javascript function??

  6. #6
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Response.Write ("<SCRIPT LANGUAGE=""JAVASCRIPT""><BR>")
    Response.Write ("function load(){") <-- Not sure about the parentheses. 
    
    more code...more code
    
    Response.Write ("}</SCRIPT>")
    Basically you have to write your JavaScript out and then use ASP to write that text out.

    Let me tell you from personal experience its a big pain in the rear end.

    <EDIT>Just found this article. It seems you can put ASP code in JavaScript.

    http://www.15seconds.com/issue/000210.htm
    Last edited by moospot; Nov 8, 2001 at 12:11.

  7. #7
    SitePoint Enthusiast stephan_100's Avatar
    Join Date
    Nov 2001
    Location
    Toronto, Ontario, Canada
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript and asp

    From what I know about ASP and Javascript, I think you can put Javascript into ASp scripts, but you can't put ASP scripts into Javascript's. I hope you have some luck with ASP, because im trying to learn it, along with SQL and I'm having a lot of trouble. If you know any good resources where I could learn these languages, please tell me. Here's some of the site's that I like using.
    [list=1][*]www.sitepointforum.com[*]www.w3schools.com[*]www.webdevelopers.com[*]and my site which isn't up yet, http://thexsystem.cjb.net[/list=1]
    Hopefully this can help you out a bit.


    Stephan


    Stephan M.
    Computer Forums -- Supplies All The Help You Need
    http://www27.brinkster.com/cforums

  8. #8
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    As wes has already pointed out:

    1. Page is called
    2. ASP is processed
    3. Page is sent to user with all final code
    4. That's it

    So, you couldn't have a client-side event trigger stuff IN PAGE, but you could redirect to another page, do some processing and come back OR just include the processing you desire in page (as wes has suggested).

    Essentially, read what wes said, it's bang on.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •