SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy javascript popup page on page load

    Hi I am trying to do a popup window, which will load when the page loads. Using the onLoad in the <Body> tag. However it doesn't seem to be working. Also when the popup loads there will be a form which the user selects an option and the form is sent to a email address with the answer chosen and then the popup closed.

    Can anyone help me please? It's quite urgent.

    Thanks

    SAMPLE OF CODE: In index page which should load the popup when page loads

    Code JavaScript:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    myPopup = '';
     
    function openPopup(url) {
        myPopup = window.open(url,'popupWindow','width=640,height=480');
        if (!myPopup.opener)
             myPopup.opener = self; 
    }
    //--></SCRIPT>
    </head>
     
     
    <body bgColor="#808080" onLoad="javascript: openPopup()">


    SAMPLE OF CODE: of popup page

    Code HTML4Strict:
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="JavaScript"><!--
    function copyForm() {
        opener.document.hiddenForm.myTextField.value = document.popupForm.myTextField.value;
        opener.document.hiddenForm.submit();
        window.close();
        return false;
    }
    //--></SCRIPT>
    </HEAD>
    <BODY>
    <FORM NAME="popupForm" onSubmit="return copyForm()">
    <INPUT TYPE="TEXT" NAME="myTextField">
    <INPUT TYPE="BUTTON" VALUE="Submit" onClick="copyForm()">
    </FORM>
    </BODY>
    </HTML>

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Ballarat, Vic. Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think your code is okay...you just aren't passing the URL of the popup page like this:

    <body bgColor="#808080" onLoad="javascript: openPopup('mypopup.html')">

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it worked thanks! Another question; in the form of the pop page, there will be a question with 4 answers to choose from, and then select submit. When the submit button is pressed the answer will be sent to a email address and then popup closed.
    How do I do the submit button to send to a email address and then close the window automatically?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Most people these days use a browser that doesn't allow popups when the page first loads. They only allow popups in response to your visitor taking an action to trigger the popup.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Ballarat, Vic. Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sharonzahra View Post
    Yes it worked thanks! Another question; in the form of the pop page, there will be a question with 4 answers to choose from, and then select submit. When the submit button is pressed the answer will be sent to a email address and then popup closed.
    How do I do the submit button to send to a email address and then close the window automatically?
    That will depend partly on what you are using to post the form, though the method is pretty much the same ... just the syntax is different. Here's how I would do it with PHP:

    Code PHP:
    <?
        if(trim($_POST["Submit"]) == "Submit")
        {
            // Add your email code here
     
            echo '<script type="text/javascript">';
            echo 'self.close();';
            echo '</script>';
            exit;
        }
    ?>

    If you have something other than javascript opening the popup window then you may need to change the javascript code to something like:

    window.opener = self;
    window.close();

    ...which should prevent the message that sometimes appears prompting the user and asking if they want to close the window.

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you explain again? I am only using HTML and Javascript. How should I submit the form to an email without using PHP but using Javascript.

    Here is my code again: In the main page:
    Code HTML4Strict:
     
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    myPopup = '';
     
    function openPopup(url) {
        myPopup = window.open(url,'popupWindow','width=640,height=480');
        if (!myPopup.opener)
             myPopup.opener = self; 
    }
    //--></SCRIPT>
    </head>
     
     
    <body bgColor="#808080" onLoad="javascript: openPopup('popupPage.html')">

    and the popupPage.html:
    Code HTML4Strict:
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="JavaScript"><!--
    function copyForm() {
        opener.document.hiddenForm.myTextField.value = document.popupForm.myTextField.value;
        opener.document.hiddenForm.submit();
        window.close();
        return false;
    }
    //--></SCRIPT>
    <style type="text/css">
    <!--
    .style1 {
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 12px;
    }
    -->
    </style>
    </HEAD>
    <BODY>
    <FORM NAME="popupForm" onSubmit="return copyForm()" action="" method="post">
      <p>
        <INPUT TYPE="radio" NAME="group1" value="YellowPages"> 
        <span class="style1">    a) Yellow Pages<br>
        </span>    
        <input type="radio" name="group1" value="other"> 
        <span class="style1">b) Other means of communication</span><br>
        <input type="radio" name="group1" value="friend"> 
        <span class="style1">c) By Friends</span><br>
        <input type="radio" name="group1" value="purchased" checked> 
        <span class="style1">d) Purchased before</span></p>
      <p>    
        <INPUT name="Submit" TYPE="submit" onClick="copyForm()" VALUE="Send">
        </p>
    </FORM>
    </BODY>
    </HTML>


    I need to choose one of the answers and the answer is to be sent to an email address. Please help. I cant use any PHP only javascript and HTML/CSS

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Ballarat, Vic. Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're going to have to use some sort of scripting language, so you might want to start perusing the PHP or ASP forums.

    Javascript is a 'client side' language, meaning that it is run in your web browser. To email the results of a form you will need to use a 'server side' scripting language such as PHP, ASP, Perl, Python etc. I'm sure there are many programmers in the scripting forums who could help with this.

    First off you will need to find out which scripting languages your host supports. Most Windows hosts will allow you to use ASP and nearly all hosts will allow you to use PHP or Perl.

    Secondly, you will need to decide whether you want to learn a little bit of another programming language or have someone else do it for you. You're better off learning a little bit yourself of course (you wouldn't need to learn much as I'm sure there is plenty of example code if you search for 'PHP email'), as it will be cheaper and more convenient in the long run, but I know that many people just don't have any interest in programming (and you could probably find someone to do it for $20 or less if it is just a basic form mailer).

  8. #8
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you explain again? I am only using HTML and Javascript. How should I submit the form to an email without using PHP but using Javascript.

    Here is my code again: In the main page:
    Code HTML4Strict:
     
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    myPopup = '';
     
    function openPopup(url) {
        myPopup = window.open(url,'popupWindow','width=640,height=480');
        if (!myPopup.opener)
             myPopup.opener = self; 
    }
    //--></SCRIPT>
    </head>
     
     
    <body bgColor="#808080" onLoad="javascript: openPopup('popupPage.html')">

    and the popupPage.html:
    Code HTML4Strict:
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="JavaScript"><!--
    function copyForm() {
        opener.document.hiddenForm.myTextField.value = document.popupForm.myTextField.value;
        opener.document.hiddenForm.submit();
        window.close();
        return false;
    }
    //--></SCRIPT>
    <style type="text/css">
    <!--
    .style1 {
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 12px;
    }
    -->
    </style>
    </HEAD>
    <BODY>
    <FORM NAME="popupForm" onSubmit="return copyForm()" action="" method="post">
      <p>
        <INPUT TYPE="radio" NAME="group1" value="YellowPages"> 
        <span class="style1">    a) Yellow Pages<br>
        </span>    
        <input type="radio" name="group1" value="other"> 
        <span class="style1">b) Other means of communication</span><br>
        <input type="radio" name="group1" value="friend"> 
        <span class="style1">c) By Friends</span><br>
        <input type="radio" name="group1" value="purchased" checked> 
        <span class="style1">d) Purchased before</span></p>
      <p>    
        <INPUT name="Submit" TYPE="submit" onClick="copyForm()" VALUE="Send">
        </p>
    </FORM>
    </BODY>
    </HTML>


    I need to choose one of the answers and the answer is to be sent to an email address. Please help. I cant use any PHP only javascript and HTML/CSS


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
  •