Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launching a Popup Window from Form 1

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I saw thread216-528760 which is identical to what I am trying to do but have had no success with with the code there or my own.

This needs to be somewhat versitile so that it can be used on a "Print Page" feature and a couple others on the site, so I am trying to pass into a function the height, width, scrolling boolean and, if necessary, the url:

Code:
function newWindow(w, h, scroll, window, url) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
        winprops = '+url+', '+window+', 'toolbar=no, location=no, directories=no, status=no, menubar=no, height='+h+', width='+w+', top='+wint+', left='+winl+', scrollbars='+scroll+', resizable=yes';
        win = window.open(winprops);
        if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}

The HTML, which is actually generated from a PHP page, has this:

Code:
<form target='paypal' action='[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr'[/URL] method='post'>
<input type='hidden' name='cmd' value='_cart'>
<input type='hidden' name='business' value='myemail@mysite.com'>
<input type='hidden' name='item_name' value='myitem'>
<input type='hidden' name='item_number' value='7B'>
<input type='hidden' name='amount' value='50'>
<input type='hidden' name='currency_code' value='USD'>
<input type='image' src='[URL unfurl="true"]https://www.paypal.com/images/x-click-but22.gif'[/URL] border='0' name='submit'  onsubmit='newWindow('600','450','yes','paypal','')';>
<input type='hidden' name='add' value='1'>
</form>

I wasn't sure if the onsubmit() was to be in the form tag or in the submit button/image tag. In all honesty, I do not know JavaScript very well so can anyone help me sort this out so that it works?

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
The onsubmit code should be moved from the input to the form. Of course, your "newWindow" function needs to be fixed so it doesn't pass everything as a single parameter, or use reserved words ("window") as parameter names:

Code:
function newWindow(w, h, scroll, [!]windowName[/!], url) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	[!]winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	win = window.open(url, windowName, winprops);[/!]
	if (parseInt(navigator.appVersion[!], 10[/!]) >= 4) [!]win.focus()[/!];
}

And then modify your form code as I've said (taking note to not nest the same type of quotes, which you also seem to be doing):

Code:
<form target="paypal" action="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr"[/URL] method="post" [!]onsubmit="newWindow('600', '450', 'yes', 'paypal', '');">[/!]

...

[!]<input type="image" src="[URL unfurl="true"]https://www.paypal.com/images/x-click-but22.gif"[/URL] border="0" name="submit">[/!]

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks a bundle! It works well now and you get a star.

Since the function doesn't need the url parameter, can it be removed something like this? I am presuming that window.open() still needs the placeholder.

Code:
function newWindow(w, h, scroll, windowName) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
    win = [COLOR=red]window.open('', windowName, winprops)[/color];
    if (parseInt(navigator.appVersion, 10) >= 4) win.focus();
}

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Thanks again! It seems to work equally well with onClick in URLs too, but does nothing in onLoad in the body tag. I don't need onLoad but I tried it just to see what it would do.

One more thing: is it possible for it to show only the lower browser bar? I realized that the Secure Site lock icon is hidden too.

Your star should be there now! I didn't realize there was a second "click" to confirm it. I thought the popup was an acknowledgement so I hadn't read it the first time. Sorry about that.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top