Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation submit form and close window

    Hi,

    This is my problem, I have a pop up form and I want the pop up close after clicking on the submit button.

    For now when I click on the submit button there is a form validation in javascript. I dont know if I can add some code in that script to tell the navigator to close the window.

    there is my code :

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    var submitcount=0;

    function reset() {
    document.spareparts.FirstName_.value="";
    document.spareparts.LastName_.value="";
    document.spareparts.Email_.value="";
    document.spareparts.Phone_.value="";
    }

    function checkFields() {
    if ( (document.spareparts.Email_.value.indexOf("@") == -1 ||
    document.spareparts.Email_.value.indexOf(".") == -1) )
    {
    alert("Please enter a proper email address.");
    return false;
    }

    else if
    ( (document.spareparts.FirstName_.value=="") ||
    (document.spareparts.LastName_.value=="") ||
    (document.spareparts.Phone_.value=="") )
    {
    alert("Please enter your name and phone number then re-submit this form.");
    return false;
    }

    else
    {
    if (submitcount == 0)
    {
    submitcount++;
    return true;
    }
    else
    {
    alert("This form has already been submitted. Thanks!");
    return false;
    }
    }

    }
    // End -->
    </script>

    I wish someone can help me,
    thanks

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Beyond Lament
    Posts
    424
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <FORM onSubmit="window.close();">
    Quíet Storm Designs ~ Art is not what you see, but what you make others see.
    · the Storms· || ·Ultraviolent Winter· || ·Was Einstein Wrong?· || ·It´s About Time!·

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried this code but that doesn't work, probably because there is already an onSubmit action. Can I put two onSubmit action?

    my code is :

    <form action="mailto:email@email.com?subject=blabla" ENCTYPE="text/plain" name="name" onSubmit="return checkFields()" method="POST">

    Thanks

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Try this:

    <script type="text/javascript" language="javascript">

    onunload = function() {
    self.close();
    }

    </script>

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Beyond Lament
    Posts
    424
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <form action="mailto:email@email.com?subject=blabla" ENCTYPE="text/plain" name="name" onSubmit="return checkFields(); window.close;" method="POST">
    Quíet Storm Designs ~ Art is not what you see, but what you make others see.
    · the Storms· || ·Ultraviolent Winter· || ·Was Einstein Wrong?· || ·It´s About Time!·

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Quiet Storm...
    These two are equivalent:

    HTML: onSubmit="return checkFields(); window.close;"

    JS: Form.onsubmit = function() {return checkFields();window.close;}

    Functions rarely get beyond a return statement...

  • #7
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your help but that doesn't work I don't know why but I tried your script and the window doesn't want to close.

  • #8
    New to the CF scene
    Join Date
    Aug 2002
    Location
    Helsinki, Finland
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe stupid suggestion but have you tried deleting your browser's temp files so that it will load the modified javascript part ?


  •  

    Posting Permissions

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