Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Preston, UK
    Thanked 0 Times in 0 Posts

    How do I open a new window with specific size ?

    Hi Guys...
    I have a form and the response opens in a new window.
    I want to open the response in a new window with a size of 400 x 500, and in the centre of the screen.
    This is the code that I have at the moment:
    PHP Code:
    <form action="contact_form2.php" method="POST"
    PHP Code:
    <input type="button" value="Send" onclick="post()"
    The script for onclick="post() is:
    <script type="text/javascript"><!--//--><![CDATA[//><!--
    function post() {
    	if (document.forms[1].name.value == "") {
    		alert("You haven't entered your NAME")
    	} else if  (document.forms[1].county.value == "") {
    		alert("You haven't entered the COUNTY where you are located.")
    	} else if  (document.forms[1].email.value == "") {
    		alert("You haven't entered your EMAIL ADDRESS so we won't be able to respond to your message.")
    	} else if  (document.forms[1].selection.value == "Please select") {
    		alert("You haven't selected a subject matter.")
    	} else if  (document.forms[1].message.value == "") {
    		alert("You haven't entered a MESSAGE in the message box.")
    	} else {
    This does open a new window, but it is a full screen with very little in it.
    It would look better in a small window.

    I will appreciate any advice.

    The MAN, The MYTH, The LEGEND:
    John C
    Support your local Country Music Club

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    Not a thing to do with PHP. Moving to Javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  3. #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,704 Times in 2,680 Posts
    Like this:-

    <script type = "text/javascript">
    function openWindow(the_url, wsize,hsize) {  
    var screen_height = window.screen.availHeight;
    var screen_width = window.screen.availWidth;
    var left_point = parseInt(screen_width / 2) - (wsize / 2);
    var top_point = parseInt(screen_height / 2) - (hsize / 2);
    var the_features = "width=" + wsize + ",height=" + hsize + ",top=" + top_point + ",left=" + left_point;
    var the_window = window.open(the_url, "", the_features);
    // openWindow('http://www.google.com/', 400,500);
    <a href = "javascript:void(0)" onclick =  "openWindow('http://www.google.com/', 400,500); return false;">Click me to open Google</a>
    I am not sure that it is a good idea to use the word post() as the name of a function, as post is a method of the form.

    alerts are obsolete and should be used only for testing purposes. Use DOM methods to display a message to your users.

    Form validation of the pattern if (document.formname.formfield.value == "") - that is blank - is barely worthy of the name, and virtually
    useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters,
    hyphen, space and apostrophe.
    Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses.
    This topic has been covered many times before in this forum.

    In theory, there isn't any difference between the theory and practice. In practice, there is.
    Last edited by Philip M; 03-27-2013 at 05:22 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


Posting Permissions

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