ASP Script Opens New Window!

Discussion in 'ASP General' started by Robert Atkinson, Jan 29, 2004.

  1. I am quite new to ASP and trying to find my feet!

    I've cobbled together some code to email some form data which works
    fine, but when I try to write a success message back to the browser,
    or use response.redirect, my browser opens a new window instead of
    writing to the current window.

    Is there something I can do to stop this? My code is pasted below.

    Many thanks, Robert.


    MAILFORM.HTM

    <form method="POST" action="contactus.asp">
    <table border="0" width="100%">
    <tr>
    <td width="24%">Your Name</td>
    <td width="42%"><input type="text" name="Name" size="37"></td>
    </tr>
    <tr>
    <td width="66%" valign="top" colspan="2">Message<br>
    <textarea rows="4" name="Message" cols="52"></textarea></td>
    </tr>
    </table>
    <table border="0" width="40%">
    <tr>
    <td width="33%" align="center"><input type="submit"
    value="Send" name="B1"></td>
    <td width="33%" align="center"><input type="reset"
    value="Reset" name="B2"></td>
    <td width="34%" align="center"><input type="button"
    value="Cancel" name="B3" onclick='self.close()'></td>
    </tr>
    </table>
    </form>



    CONTACTUS.ASP

    <%
    smtp_server_address = "localhost"
    on error resume next
    response.buffer = true
    Set Jmail = Server.CreateOBject( "JMail.Message" )
    Jmail.Logging = true
    Jmail.Silent = true
    JMail.From = "C&NEE_Contact_Us"
    Jmail.AddRecipient ""
    JMail.Subject = "Information Request"
    FOR EACH el IN Request.Form
    body = body & el & ": " & Request.form(el) & vbcrlf
    NEXT
    JMail.Body = Body
    JMail.Priority = 1
    if not Jmail.Send(smtp_server_address) then
    ' There was an error - print the error log
    Response.write ("Error:<br>" & Jmail.log)
    else
    ' The message has been sent - redirect to confirmation page
    Set JMail = Nothing
    response.write ("<script>document.write('Your message has been
    sent');</script>")
    end if
    Set JMail = Nothing
    %>
    Robert Atkinson, Jan 29, 2004
    #1
    1. Advertising

  2. Robert Atkinson

    Curt_C [MVP] Guest

    why are you using a Response.Write to write a <script> with document.write?
    Why not just use the Response.Write ?
    Your problem isn't the Response.Write by the way, it's the client-side
    <script> tag that's opening the new window

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    www.Darkfalz.com


    "Robert Atkinson" <> wrote in message
    news:...
    > I am quite new to ASP and trying to find my feet!
    >
    > I've cobbled together some code to email some form data which works
    > fine, but when I try to write a success message back to the browser,
    > or use response.redirect, my browser opens a new window instead of
    > writing to the current window.
    >
    > Is there something I can do to stop this? My code is pasted below.
    >
    > Many thanks, Robert.
    >
    >
    > MAILFORM.HTM
    >
    > <form method="POST" action="contactus.asp">
    > <table border="0" width="100%">
    > <tr>
    > <td width="24%">Your Name</td>
    > <td width="42%"><input type="text" name="Name" size="37"></td>
    > </tr>
    > <tr>
    > <td width="66%" valign="top" colspan="2">Message<br>
    > <textarea rows="4" name="Message" cols="52"></textarea></td>
    > </tr>
    > </table>
    > <table border="0" width="40%">
    > <tr>
    > <td width="33%" align="center"><input type="submit"
    > value="Send" name="B1"></td>
    > <td width="33%" align="center"><input type="reset"
    > value="Reset" name="B2"></td>
    > <td width="34%" align="center"><input type="button"
    > value="Cancel" name="B3" onclick='self.close()'></td>
    > </tr>
    > </table>
    > </form>
    >
    >
    >
    > CONTACTUS.ASP
    >
    > <%
    > smtp_server_address = "localhost"
    > on error resume next
    > response.buffer = true
    > Set Jmail = Server.CreateOBject( "JMail.Message" )
    > Jmail.Logging = true
    > Jmail.Silent = true
    > JMail.From = "C&NEE_Contact_Us"
    > Jmail.AddRecipient ""
    > JMail.Subject = "Information Request"
    > FOR EACH el IN Request.Form
    > body = body & el & ": " & Request.form(el) & vbcrlf
    > NEXT
    > JMail.Body = Body
    > JMail.Priority = 1
    > if not Jmail.Send(smtp_server_address) then
    > ' There was an error - print the error log
    > Response.write ("Error:<br>" & Jmail.log)
    > else
    > ' The message has been sent - redirect to confirmation page
    > Set JMail = Nothing
    > response.write ("<script>document.write('Your message has been
    > sent');</script>")
    > end if
    > Set JMail = Nothing
    > %>
    Curt_C [MVP], Jan 29, 2004
    #2
    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. robertm
    Replies:
    1
    Views:
    821
    Vidar Petursson
    Aug 11, 2003
  2. netnews.comcast.net

    Buttons Opens a new window

    netnews.comcast.net, Jan 11, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,100
    Jeffrey Tan[MSFT]
    Jan 13, 2004
  3. Vijay Kerji

    Window.Close Opens New Annoying Window

    Vijay Kerji, Dec 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,118
    Eliyahu Goldin
    Dec 1, 2004
  4. kiran
    Replies:
    4
    Views:
    179
    kiran
    Jul 24, 2003
  5. gopal srinivasan
    Replies:
    0
    Views:
    229
    gopal srinivasan
    Nov 5, 2004
Loading...

Share This Page