Call a javascript function from ASP page

Discussion in 'ASP General' started by Mark, Jul 27, 2006.

  1. Mark

    Mark Guest

    I've searched a bunch of groups, and they say this can be done, but for
    some reason, I can't get it to work.

    Here's my ASP page:

    <% @ Language=VBScript %>
    <Script language=javascript>
    function cont(strTitle){
    if("undefined"!=typeof strTitle){
    window.opener.location='somepage.asp?title=' + strTitle;
    window.close();
    }
    else
    window.close();
    }
    </script>

    <%
    strTitle=Upload.form("title")
    Do Stuff

    cont(strTitle)
    %>

    <body ONLOAD="cont(<%=strTitle%>">
    </body>

    What I want to happen, is if this page gets called from a form and
    title is null or undefined, then close the window. Otherwise, do
    something, then close the window with the javascript call.

    Thanks,

    - Mark
     
    Mark, Jul 27, 2006
    #1
    1. Advertising

  2. Mark

    Larry Bud Guest

    Mark wrote:
    > I've searched a bunch of groups, and they say this can be done, but for
    > some reason, I can't get it to work.
    >
    > Here's my ASP page:
    >
    > <% @ Language=VBScript %>
    > <Script language=javascript>
    > function cont(strTitle){
    > if("undefined"!=typeof strTitle){
    > window.opener.location='somepage.asp?title=' + strTitle;
    > window.close();
    > }
    > else
    > window.close();
    > }
    > </script>
    >
    > <%
    > strTitle=Upload.form("title")
    > Do Stuff
    >
    > cont(strTitle)
    > %>
    >
    > <body ONLOAD="cont(<%=strTitle%>">
    > </body>
    >
    > What I want to happen, is if this page gets called from a form and
    > title is null or undefined, then close the window. Otherwise, do
    > something, then close the window with the javascript call.


    You're missing a closing paren ) in the onload
     
    Larry Bud, Jul 27, 2006
    #2
    1. Advertising

  3. Mark

    Mark Guest

    Good eye, but sadly, that's just my typing the code into the post, not
    in my code.

    Thanks.
     
    Mark, Jul 27, 2006
    #3
  4. > Good eye, but sadly, that's just my typing the code into the post, not
    > in my code.


    Another error I spotted is that I assume strTitle should have quotes around
    it. So, it should be

    <body onload="cont('<%=strTitle%>');">

    (Assuming strTitle can't have ' in it, if so, then

    <body onload="cont('<%=Replace(strTitle, "'", "\'")%>');">

    But since you didn't tell us what "doesn't work" means, I have no idea if
    I'm wasting my time looking at the syntax or if I should focus on your
    approach (because you can't call cont() -- a client-side JavaScript
    function -- from ASP, which runs on the server, not on the client).

    It would be helpful if you better define "can't get it to work". Are you
    getting an error message? If so, what is it? Or, how is it not working the
    way you would expect? Is the window not launching the right page, or is it
    only launching when the title is empty instead of the opposite, or is it
    always opening, or is it never opening?

    Have you considered this approach instead?

    <script language=javascript>
    function checkit()
    {
    <%
    strTitle=Upload.form("title")
    ' Do Stuff

    if strTitle <> "" then
    %>
    window.opener.location.href = 'somepage.asp?title=<%=strTitle%>';
    <% end if %>
    window.close();
    }
    </script>
    <body onload="checkit();">
     
    Aaron Bertrand [SQL Server MVP], Jul 27, 2006
    #4
  5. Mark

    Mark Guest

    The issue is, as you say, calling client-side java with ASP.

    Your approach looks very promicing. I'm going to give it a shot.

    Thanks,

    - Mark
     
    Mark, Jul 27, 2006
    #5
  6. Mark

    Mark Guest

    Works great. Thanks for the instruction.

    - Mark
     
    Mark, Jul 27, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. grbgooglefan
    Replies:
    2
    Views:
    456
    Pascal Bourguignon
    Jan 30, 2008
  2. grbgooglefan
    Replies:
    4
    Views:
    475
    Kenny McCormack
    Jan 30, 2008
  3. grbgooglefan
    Replies:
    0
    Views:
    426
    grbgooglefan
    Jan 30, 2008
  4. Alok
    Replies:
    3
    Views:
    288
  5. THAKUR PRASHANT SINGH

    Class Function call vs Normal Function call

    THAKUR PRASHANT SINGH, Feb 26, 2010, in forum: Ruby
    Replies:
    7
    Views:
    218
    THAKUR PRASHANT SINGH
    Feb 27, 2010
Loading...

Share This Page