www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 09-05-2009, 01:47 AM
    cocotu cocotu is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 8
    How to get an alert box after submiting a form

    At our website: chatwincompany.com
    we want to have an alert window e.g "Thanks for Subscribing"
    instead of having a new window coming from the 'insert.php' script. I tried may ways and I know this should be simple, but I'm a newbie at JavaScript. Below is the current code:

    <form action="insert.php" enctype="multipart/form-data" id="form" method="post">
    <div class="form"><img src="images/form_title_test.gif" alt="" /><br />
    <div class="div_input"><input name="email" type="text" class="input_1" value="Enter email" /></div>
    <a href="#" onclick="document.getElementById('form').submit()"><img src="images/link_subscribe_test.gif" alt="" /></a>
    </div></form>

    Thanks in advance....
    Reply With Quote
      #2  
    Old 09-22-2009, 04:47 PM
    aihazm@yahoo.co aihazm@yahoo.co is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 7
    form onsubmit="yourJavacrit();"
    Reply With Quote
      #3  
    Old 09-22-2009, 05:48 PM
    cocotu cocotu is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 8
    you mean this way?:
    <form action="insert.php" onsubmit="myJavaScript()" enctype="multipart/form-data" id="form" method="post">

    or

    <form action="insert.php" enctype="multipart/form-data" id="form" method="post">
    <form onsubmit="myJavaScript();">

    thanks
    Reply With Quote
      #4  
    Old 09-22-2009, 06:09 PM
    aihazm@yahoo.co aihazm@yahoo.co is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 7
    Code:
    <form action="insert.php" onsubmit="alert('Thanks for Subscribing');" enctype="multipart/form-data" id="form" method="post">
    and if needed redirection continue with onsubmit="alert('Thanks for Subscribing'); document.location.href='http://new location';"

    Last edited by aihazm@yahoo.co; 09-22-2009 at 06:12 PM.
    Reply With Quote
      #5  
    Old 11-03-2009, 01:35 PM
    cocotu cocotu is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 8
    hey...sorry it took me long to respond i was away. it still redirects me to the insert.php page. this is my current code:
    Code:
    <form action="insert.php" onsubmit="alert('Thanks for Subscribing');" enctype="multipart/form-data" id="form" method="post">
                                    <div class="form"><img src="images/form_title_test.gif" alt="" /><br />
                                    <div class="div_input"><input name="email" type="text" class="input_1" value="Enter email" /></div>
                                    <!--<a href="#" onclick="document.getElementById('form').submit()"><img src="images/link_subscribe_test.gif" alt="Subscribe" /></a>-
    ->Press Enter
    how can i just have the alert window without redirecting anywhere. and if i do this will the insert.php still work? thanks...
    Reply With Quote
      #6  
    Old 11-03-2009, 01:38 PM
    criterion9 criterion9 is offline
    Registered User
     
    Join Date: Jan 2009
    Posts: 997
    The PHP will still need to process the form (requiring a refresh) unless you want to post the data using AJAX. The best practice is to provide a server-side solution and then using AJAX if available to provide a smoother more user-friendly solution.
    Reply With Quote
      #7  
    Old 11-03-2009, 03:20 PM
    cocotu cocotu is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 8
    i like those links criterion9...thanks! i going to experiment and see what happens...thanks!
    Reply With Quote
      #8  
    Old 11-04-2009, 02:32 PM
    cocotu cocotu is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 8
    i will work on that, but for now How can i make the confirmation page (insert.php) a pop-up window? i tried a few ways and doesn't seem to work for me....
    thanks
    Reply With Quote
      #9  
    Old 11-04-2009, 07:06 PM
    criterion9 criterion9 is offline
    Registered User
     
    Join Date: Jan 2009
    Posts: 997
    You won't be able to make it a popup as far as I know unless your form is on a different page and you set the target attribute to "_blank" on your form (but I'm not sure that will work in most situations or any at all in fact). This is not a good idea though and you should really look at just using the same page to do what you need (in this case tell the user the form submitted successfully). Once you get that working you can use AJAX to create a "popup" div that appears instead of a page refresh.
    Reply With Quote
      #10  
    Old 11-06-2009, 02:51 PM
    cocotu cocotu is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 8
    Quote:
    you should really look at just using the same page to do what you need (in this case tell the user the form submitted successfully)
    I have this working already: chatwincompany.com
    if you fill out the newsletter form it will confirm the user, but it will take the user to the insert.php page and i wanted an alert box(which i can't still figure how to make work the way is supposed to).
    How would you do that 'AJAX popup div'?
    thanks...
    Reply With Quote
      #11  
    Old 11-06-2009, 03:14 PM
    criterion9 criterion9 is offline
    Registered User
     
    Join Date: Jan 2009
    Posts: 997
    After you employ the Ajax from above use one of a number of "javascript popup div" scripts.

    http://www.dynamic-tools.net/toolbox/popUp/
    http://javascript.internet.com/misce...popup-div.html
    http://www.javascripttoolbox.com/lib/popup/example.php
    Reply With Quote
      #12  
    Old 11-10-2009, 01:33 PM
    cocotu cocotu is offline
    Registered User
     
    Join Date: Sep 2009
    Posts: 8
    criterion9...i appreciate your help. i have this alert window working, but how do i avoid being redirected to the insert.php page? as you can see at chatwincompany.com when the user subscribes to the newsletter you get the alert window, but then you are taken to the insert.php page!
    i think this should be easy to take care, i just don't see the way. how can i stop from redirecting to the insert.php and if i do would the insert.php still do what is supposed to do? (insert emails in database?) thanks again....
    Reply With Quote
      #13  
    Old 11-10-2009, 02:40 PM
    criterion9 criterion9 is offline
    Registered User
     
    Join Date: Jan 2009
    Posts: 997
    If you are using an onsubmit handler use the return value to cancel the submit. As in:
    Code:
    <form onsubmit="return yourFunction()">
    Then you submit your form using AJAX as described above and make sure to return false in your function to prevent the browser from submitting it as well.
    Reply With Quote
    Reply

    Bookmarks

    Tags
    alert box, form


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 08:35 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.