SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Give users a window choice?

    I have a form that opens a new window when submitted.

    However, many people don't like new windows opening. So, I would like to create an option that would let users control whether the form result opens in a new window or in the same window. Can this be done?

    I was thinking of adding a checkbox and if it would be chacked = new window, not checked = same window. How can I accomplish this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    UK
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, this does exactly what you specified.

    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    function openWin() {
    if (document.egform.chkbox.checked) {
    
    	ShowWin = window.open('http://google.co.uk','page','width=600,height=400');
    	return (true); 
    } else {
    	window.location ='http://webdesignforums.net';
    	return (false);}
    }
    </script>
    </head>
    
    <body>
    <form name="egform" action="#" method="post" onSubmit="return openWin();">
    <input type="text" size="20" name="sometext" value="enter text" /><br />
    <input type="checkbox" name="chkbox" /><br />
    <input type="submit" name="submit" value="Check" />
    </form>
    </body>
    </html>

  3. #3
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot!


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
  •