Jump to content
Larry Ullman's Book Forums

Recommended Posts

Having a problem with opening an addition window. This next coding portion is working correctly and opening the href in a new window.

 

<td><a href="form_selection.php" onClick="window.open(this.href, 'popupwindow2','width=1100,height=800,left=500, top=50, scrollbars=yes,resizable=yes');return false;"><h4> Select and Prepare New Legal Form </h4> </a></td>

 

===============================================================================

 

Now this segment of coding from a form is not working. The form action is opening the correct php page, but it is not opened in a new window as desired. Can anyone see what is wrong as it is basically the same as the href process. I have changed dimensions, I have changed "this.form.action" to many different variations with spaces, quotes, brackets, etc, but the page is ran correctly, just not in a new window.

 

<form method="post" action="/form/AZCondFinRel.php" onSubmit="window.open( this.form.action,'popupwin','width=1000,height=700,left=50,top=5,scrollbars=yes,resizable=yes');return false;" >

 

Mahalo

Link to comment
Share on other sites

First, I would confirm whether the onSubmit() is taking effect at all. For example, you could change the onSubmit() to call an alert() or just return false. Off the top of my head, I don't know what the limitations are on submit event handlers, so my suspicion is that's the problem, not the specific code for opening a new window.

Link to comment
Share on other sites

Some browsers won't accept onSubmit; it needs to be onsubmit. That might not be the problem though.

 

Your action link could also be the problem, but can't confirm that from here. Also, you really should try separating your JS from your HTML. It's late here, so sometime tomorrow, I'll try and code up a simple example to demonstrate what I mean. Hopefully, in the meantime, I can also find the issue with your code.

  • Upvote 1
Link to comment
Share on other sites

I have changed this non-working code around from the previous that was submitted above. Now a new window is being opened, but errors with "Internet Explorer cannot display the webpage" The correct URL is showing in the browser address bar.

 

<form action="./form/AZCondFinRel.php" onsubmit="window.open(this.action,'popupwin','width=1000,height=700,left=500,top=5,scrollbars=yes,resizable=yes');return false;" method="post" >

If I remove the onsubmit command and attributes, the form opens correctly but in existing window.

 

So still puzzled.

Link to comment
Share on other sites

Sorry for taking so long to respond. I created the following sample script to show how JS should be separated from the HTML:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

 <head>

   <title>onsubmit test</title>

   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 </head>

 <body>

   <form action="http://en.wikipedia.org/wiki/Wiki" method="post">

     <p><label for="firstname">First name: </label><input type="text" name="firstname" id="firstname"></p>

     <p><input type="submit" value="Submit"></p>

   </form>

   <script type="text/javascript">

     document.forms[0].onsubmit = function() {

       window.open(this.action,'','width=1000,height=700,left=500,top=5')

       return false;

     };

   </script>

 </body>

</html>

 

Also, if you do use the inline defintion, which I do not recommend, then you shouldn't use return false. You need to return a JS function/method. Please Google this for more info. I'm not going to explain it here though, because you shouldn't be using inline definitions anyway.

 

Also, the first argument for window.open is the URL, and URLs cannot contain relative paths (i.e., ./ and ../).

 

As a more minor point, the default for scrollbars and resizeable is yes, so you don't need to specify those. Also, top is only supported in IE, so you need to consider that.

 

Lastly, if you don't want to use forms[0] in the JS, you can assign a name to the form and use that. For example:

 

<form action="http://en.wikipedia.org/wiki/Wiki" method="post" name="homer">

...

document.homer.onsubmit = function() {

 

That help?

  • Upvote 1
Link to comment
Share on other sites

Sorry for taking so long to respond. I created the following sample script to show how JS should be separated from the HTML:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

 <head>

   <title>onsubmit test</title>

   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 </head>

 <body>

   <form action="http://en.wikipedia.org/wiki/Wiki" method="post">

     <p><label for="firstname">First name: </label><input type="text" name="firstname" id="firstname"></p>

     <p><input type="submit" value="Submit"></p>

   </form>

   <script type="text/javascript">

     document.forms[0].onsubmit = function() {

       window.open(this.action,'','width=1000,height=700,left=500,top=5')

       return false;

     };

   </script>

 </body>

</html>

 

Also, if you do use the inline defintion, which I do not recommend, then you shouldn't use return false. You need to return a JS function/method. Please Google this for more info. I'm not going to explain it here though, because you shouldn't be using inline definitions anyway.

 

Also, the first argument for window.open is the URL, and URLs cannot contain relative paths (i.e., ./ and ../).

 

As a more minor point, the default for scrollbars and resizeable is yes, so you don't need to specify those. Also, top is only supported in IE, so you need to consider that.

 

Lastly, if you don't want to use forms[0] in the JS, you can assign a name to the form and use that. For example:

 

<form action="http://en.wikipedia.org/wiki/Wiki" method="post" name="homer">

...

document.homer.onsubmit = function() {

 

That help?

Link to comment
Share on other sites

It will be impossible for me to use absolute paths instead of releative, because I will be loading and display hundreds of forms for the user and these will be all in various directories. To use absolute would be a nightmare in testing using Localhost and then the actual live URL. Any other options??

Link to comment
Share on other sites

Can't you store different pieces of the URL in strings in a config file, and then just add the different pieces together. For example:

 

var sBaseURL = 'http://www.example.com/';

var sUsersScript = 'users.php';

var sAdminScript = 'admin.php';

var sURL = sBaseURL + sUsersScript;

window.open(sURL,...);

 

What do you think?

  • Upvote 1
Link to comment
Share on other sites

Sorry for giving a somewhat incomplete answer before. Apparently relative URLs are perfectly acceptable for window.open.

(Source: http://www.tizag.com/javascriptT/javascriptpopups.php)

 

As such, the URL itself is probably the issue. I'd start playing around with various values until you can debug it. I'm still not sure whether ./ and ../ are supported though. Again, I recommend playing around with the values for the URL.

Link to comment
Share on other sites

 Share

×
×
  • Create New...