Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 21st, 2005, 11:30 PM   #1
raikkonen
Newbie
 
Join Date: Jun 2005
Posts: 29
Rep Power: 0 raikkonen is on a distinguished road
popup

i'm struck at this place,.. couldnt solve this problem. guys need your help. thanks. i couldnt make the window pop up..

<html> <head><SCRIPT LANGUAGE="JavaScript">
<!--
function reportCard() {

var header = ("<html><head><title></title></head>");
var body = ("<body>Helloworld</body>");
var footer = (</html>);
var pageBody = ("" + header + "" + body + "" + footer + "");
reportWin = window.open("","","width=620,height=400,toolbar=yes,menubar=yes,scrollbars=yes");
reportWin.document.write(pageBody);
reportWin.document.close();
//reportWin.document.write(pageBody);
//reportWin.document.close();
}

-->

</script>
</head>
<body>

<form method="post">

<INPUT TYPE="button" VALUE="Report Card" onClick=reportCard(this)>
</form>
</body></html>
raikkonen is offline   Reply With Quote
Old Aug 22nd, 2005, 4:58 AM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
<html> <head><SCRIPT LANGUAGE="JavaScript">
 <!--
 function reportCard() {
 
 var header = ("<html><head><title></title></head>");
 var body = ("<body>Helloworld</body>");
 var footer = (</html>);
 var pageBody = ("" + header + "" + body + "" + footer + "");
 reportWin = window.open("","","width=620,height=400,toolbar=yes,menubar=yes,scrol lbars=yes");
 reportWin.document.write(pageBody);
 reportWin.document.close();
 //reportWin.document.write(pageBody);
 //reportWin.document.close();
 } 
 
 -->
 
 </script>
 </head>
 <body>
 
 <form method="post">
 
 <INPUT TYPE="button" VALUE="Report Card" onClick=reportCard(this)>
 </form>
 </body></html>
1. You don't need those parentheses when creating a string. It won't raise an error, but you can just do `var header="<html>...</head>"`
2.That is an error. You're missing quotation marks.
3. You don't need to put emptry strings next to each when you're concatanating. You can just do `var pageBody = header + body + footer`
4. No spacing there.
5. I'm fairly sure you can't just open a window and call win.document.write. You'll probably need to open a new window, append a body element, and then use innerHTML to generate the content on the fly.
6. You should be doing `onclick="reportCard()"`, not reportCard(this) as the reportCard function does not take a parameter. That won't raise an error, however.
Cerulean is offline   Reply With Quote
Old Aug 22nd, 2005, 7:37 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Cerulean's recollection on point 5 is correct. Here's a working piece of code that generates a popup with a specific message. Obviously, the variable, "cred", could be an argument and dynamically stuffed with whatever you like.
function credits ()
{
	var cred;
	var credWin;
	var specWin;
	cred = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" type="text/css" href="dawei.css"><title>Credits</title></head><body><div style="background-image: url(&quot;images/paper.jpg&quot;); padding: 50px 50px 50px 50px; border: 2px solid #000000;"><table border="0"><tr><td><h3><center>Credits</center></h3></td></tr><tr><td align="left">Thanks to all the DevShed C/C++ forum members for their suggestions and for contributing to the correctness of the material.<p>A special thanks to Grumpy and Infamous, Grumpy for the time he spent in attempting to promote clarity as well as accuracy; Infamous for his suggestions "from the viewpoint of a n00b" and particulary for his suggestion that I add a few definitions that show via flyout when moused over.</p><p>I unashamedly ripped and adapted some presentational thangys from Scorpions4ever\'s tutorial on <a href="http://www.mayukhbose.com/tutorials/overloading/">overloading operators</a>, which I highly recommend.</td></tr></table></div></body></html>';
	specWin = "width=700,height=450,top=30,left=30," +
	  			"screenx=30,screeny=30," +
			  	"resizable=yes,scrollbars=yes";
	credWin = enlarge ("", specWin);
	credWin.document.write (cred);
	credWin.document.close ();
}
The enlarge function is just a wrapper for the window opening function that uses a default set of window decorations, if none are suppied in the argument.
function enlarge (wURL, sp)
{
	var specs = "width=800,height=600,top=30,left=30," +
	  			"screenx=30,screeny=30," +
			  	"resizable=yes,scrollbars=yes";
	if (sp) specs = sp;
	popWin = open (wURL, "popWindow", specs);
	popWin.focus ();
	return popWin;
}
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:33 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC