?
Solved

One form, 2 buttons, each with different destinations.

Posted on 2006-05-17
11
Medium Priority
?
224 Views
Last Modified: 2012-05-05
Hi Experts,
I found this code online somewhere and need help modifying it. I want to specify the dimensions of the window that pops under the OnButton1 function. I've tried several different ways to get my window specs in there but none have worked.

Can anyone help?
Thanks!

(hopefully these points will be enough... it's all that I have left!)

---------------------------------------------
<script language=javascript>
<!--
function OnButton1()
{
      document.add.action = "preview.asp"
      document.add.target = "_blank";
      document.add.submit();
      return true;
}

function OnButton2()
{
      document.add.action = "<%=MM_editAction%>"
      document.add.target = "_self";
      document.add.submit();
      return true;
}
-->
</script>
<noscript>You need Javascript enabled for this to work</noscript>


<input name="Preview" type="submit" value="Preview" onclick="return OnButton1();">
<input type="submit" name="Submit" value="Submit" onclick="return OnButton2();">
</form>
0
Comment
Question by:shadie
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16700453
You can try using this command inside preview.asp

<body onload="window.resizeTo(550,400);">

A form with target="_blank" does not allow for easy manipulation thru javascript. The window.open method which allows sizing however does not realy work easily with forms.

-r-
0
 
LVL 5

Expert Comment

by:shaggy_the_sheep
ID: 16700487
Hi

Are you trying to use the button to create a complete new window?
if so you could use this....

function openWindow(width,height,url){
var top = (screen.Height/2)-(height/2);
var left = (screen.Width/2)-(width/2)

window.open(url,'','width=' + width + ',height=' + height + ',top=' + top + ',left=' + left,'');

}

Now on the buttons...

Change their type to button rather than submit and make their onclick event
onclick="openWindow(WIDTH,HEIGHT,'URL');

Note: Width and Height are not in single quotes, whereas Url is.

Richard
0
 
LVL 29

Accepted Solution

by:
Pravin Asar earned 440 total points
ID: 16701103
function OpenCenWindow (url, winname, width, height) {  
  var pStr = 'resizable, status=no,width=' + width + ', height=' + height +
             ', alwaysRaised=1, toolbar=no, menubar=no, status=no';
  var sw = window.open (url, winname, pStr);
  var x = 0.5 *(window.screen.width - width);
  var y = 0.5 *(window.screen.height - height);
  sw.moveTo (x,y);
  return sw;
}

function OnButton1()
{
     document.add.action = "preview.asp";
     // Open a new window with specific dimension.
     var nw= OpenCenWindow ('','YourDest', 800, 600);
     document.add.target = "YourDest";
     document.add.submit();

     // Set focus to new window
     nw.focus();
     return true;
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:shaggy_the_sheep
ID: 16701289
What do you want the function do?

Actually open a totally new window? With a specific Url?

Any more info would be useful

Richard
0
 
LVL 1

Author Comment

by:shadie
ID: 16701399
I have a web form where my Copy Writers will submit copy that will ultimately get uploaded to our site. Most of the writers are not up on their html, plus some of them will ultimately copy text from Quark Xpress. I am trying to make it 1. easy on them and 2. ensure that the copy conforms to the html standard in place at our site.

I am putting a "preview" link for the textarea where they enter their text. This way they can preview the copy for typos, etc. before submitting the form. The method I submitted with my question works, just that I can't seem to grab control of the widow that pops open. (they're a whiny bunch and I am trying to make sure that they see the preview window on top of the form window by making it smaller, say 500/300 pixels)
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 16701452
I have faced a similar situation,

I think you may find my code useful.

1. This opens a new window (centered on the screeen),
2. And sends a submitted form to the newly opened window.
3. Sets a focus() to new window.

0
 
LVL 5

Expert Comment

by:shaggy_the_sheep
ID: 16701548
Oh right

if the HTML they are uploading will be in a text area you need to do this....

function previewHtml(){
var width = 500;
var height = 300;

var top = (screen.Height/2)-(height/2);
var left = (screen.Width/2)-(width/2)

var newwindow = window.open('','','width=' + width + ',height=' + height + ',top=' + top + ',left=' + left,'');

newwindow.document.write (document.FORM.TEXTAREA.VALUE);
newwindow.focus()

}

now make your button
<input type="button" id="Preview" value="Preview" onclick="previewHtml()">

That should do what you want

Richard
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 16701678
Here is my post (look at the previous post), applied to your question..

<html>
<head>
<title>Form Submit Document</title>
</head>

<body>
<script language=javascript>
<!--
var sw;
function OpenCenWindow (url, winname, width, height) {
  var x = 0.5 *(window.screen.width - width);
  var y = 0.5 *(window.screen.height - height);
  var posStr = ", screenX=" + x + ", screenY=" + y;
  if (document.all) {
             posStr = ", left=" + x + ", top=" + y;
  }
  var pStr = 'resizable, status=no,width=' + width + ', height=' + height +
             ', alwaysRaised=1, toolbar=no, menubar=no, status=no';
  var sw = window.open (url, winname, pStr+posStr);
 
  return sw;
}

function OnButton1()
{
     document.add.action = "preview.asp";
     // Open a new window with specific dimension.
     var nw= OpenCenWindow ('','YourDest', 800, 600);
     document.add.target = "YourDest";
     document.add.submit();

     // Set focus to new window
     nw.focus();
     return true;
}

function OnButton2()
{
     document.add.action = "<%=MM_editAction%>"
     document.add.target = "_self";
     document.add.submit();
     return true;
}
-->
</script>
<noscript>You need Javascript enabled for this to work</noscript>
<form name="add">
<input name="Preview" type="submit" value="Preview" onclick="return OnButton1();">
<input type="submit" name="Submit" value="Submit" onclick="return OnButton2();">
</form>

</body>
</html>
0
 
LVL 1

Author Comment

by:shadie
ID: 16701679
pravinasar
It worked! Thank you. I took out the part where the window is forced to the center of the screen. Something about that jerky motion after the page loads that drives me nuts... but all-in-all, the code works great.

shaggy_the_sheep, I was working with your advice and simply changed that preview button to a button instead of submit. The window popped correctly but the textarea value was not passed to the pop window.

Thanks all for your help!
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 16701704
Thanks,

Use OpenCenWindow() from my last post.

This takes of a minor issue (when a sw is already created sw.moveTo () will fail..access
voilation), hence I used the posStr to center a window.

var sw;
function OpenCenWindow (url, winname, width, height) {
  var x = 0.5 *(window.screen.width - width);
  var y = 0.5 *(window.screen.height - height);
  var posStr = ", screenX=" + x + ", screenY=" + y;
  if (document.all) {
           posStr = ", left=" + x + ", top=" + y;
  }
  var pStr = 'resizable, status=no,width=' + width + ', height=' + height +
             ', alwaysRaised=1, toolbar=no, menubar=no, status=no';
  var sw = window.open (url, winname, pStr+posStr);
 
  return sw;
}
0
 
LVL 1

Author Comment

by:shadie
ID: 16701787
nice! I like that much better
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question