简体   繁体   中英

Javascript pop-up

I am currently working on a php e-mail system. I created a javascript pop-up page where I can add users (mail addresses). Now I want to post the selected user('s) from the javascript pop-up window to open the website of course I get the page where you want to post in the pop up to see.

Now I want to now, if there is click on the submit than close the popup and allows the data to the open web page whit post?

How can i do this??

    <script>
        $("a[href=#myModal]").click(function() {
            var str = $(this).attr("data-phpvar");
            var substr = str.split('||');

            $("[name=textinput1]").val(substr[0]);
            $("[name=textinput2]").val(substr[1]);
        });
    </script>

   <form>
        <table>
            <tr>
                <td>
                    <a href="#myModal" title="#" role="button" data-toggle="modal" data-phpvar="<?php echo $value['something'] . '||' . $value['something']);?>"></a>
                </td>
            </tr>
        </table>
    </form>

OnClick of the href link or button you will send the data-php-var to the jQuery function. This function will send the values into the popup. In the popup is a text-field with the same name the jQuery function will put your values into de field.

You'll want to use AJAX to post the form asynchronously so the user doesn't have to wait for it to process or view the processing page. jQuery makes it very easy to use AJAX as shown here .

Also, after the work is done in the popup window you can access and refresh the parent window using the window.opener function:

<script language="JavaScript">
    function refreshParent() {
      window.opener.location.href = window.opener.location.href;
      window.close();
    }
</script>

you might want to look to the overlay plugin at jquery tools . Pop-ups are blocked by the browser most of the times. And imo an overlay is a more elegant solution. Furthermore, you can just post your form as you would normal do on a webpage, nu extra js needed there!

--- edit; when reading your question more closely; you don't even need to post the page! Just assign a click event to the submit button (which doesn't necessarily needs to be a submit button). In your event function you can read out the filled in addresses (or other information), paste it into the desired fields (whether it be a form field or just a regular div) and close the overlay again. Now you don't even need a page refresh!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM