Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > New Window Instead of Alert Box?

Reply
Thread Tools

New Window Instead of Alert Box?

 
 
Tavish Muldoon
Guest
Posts: n/a
 
      03-03-2005
Hello,

I have same Javascript that performs a little quiz after choose
selections from radio buttons. It displays the number of answer that
one got right. But it puts them in an alert box - I want it to be in
a new window.

The alert box works fine and show the correct data.

The button:

<input type=button onClick="Showtotal()" value="TOTAL">

Showtotal():

function Showtotal(){
var answerText = "What is the
total?\n------------------------------------\n";
for(i=1;i<=5;i++){
answerText=answerText+"\nQuestion :"+i+"\n";
if(ans[i]!=yourAns[i]){
answerText=answerText+"\nThe correct answer was
"+ans[i]+"\n"+explainAnswer[i]+"\n";
}
else{
answerText=answerText+" \nCorrect! \n";
score++;
}
}
[some code snipped]
alert(answerText); <---I want this data to show up in a new
window....


I tried adding :

var w = window.open('','mywin','width=500,height=500'); to my declared
variables

then instead of the alert box line, it was replaced with:

w.document.write('<html><head><title>Choice</title></head><body><pre>'+answerText+'</pre></body></html>');
w.document.close();
w.focus();

</script>


What happens - when I open the original window - it opens up a blank
new windows with the orignal behind it. Pressing the TOTAL button
does nothing.

Help?

Thanks,

Tmuld.
 
Reply With Quote
 
 
 
 
kaeli
Guest
Posts: n/a
 
      03-03-2005
In article <(E-Mail Removed) >,
http://www.velocityreviews.com/forums/(E-Mail Removed) enlightened us with...
>
> What happens - when I open the original window - it opens up a blank
> new windows with the orignal behind it. Pressing the TOTAL button
> does nothing.
>


Do this instead.
(watch for word-wrapping!)

Add this declaration to your code outside ANY function:
var h_window = null;

(allows window re-use)

Add this function to your code:

function showTotalWindow(answerText)
{
if (!h_window || h_window == null || typeof h_window == "undefined" ||
h_window.closed || !h_window.document)
h_window = window.open("","Choice","height=300,width=
300,scrollbars=yes,resizable=yes");
var doc = h_window.document;
doc.open();
doc.writeln("<html><head><title>Choice</title>");
doc.writeln("</head><body>");
doc.writeln("<pre>" + answerText + "</pre>");
doc.writeln("</body></html>");
doc.close();
h_window.focus();
return;
}

Change the line of code in ShowTotal() from
alert(answerText);
to
showTotalWindow(answerText);

Note: the above code modified from my help window popups, so it should work
in MSIE, Opera, and Firefox, at least.

HTH
--
--
~kaeli~
He had a photographic memory that was never developed.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Window.Open get new tab instead of new window in FireFox Fredzidd@gmail.com Javascript 1 02-29-2008 03:06 AM
Alert..General Alert?..New Discovery?. =?Utf-8?B?U3BhbW1lcipLaWxsZXI=?= Wireless Networking 0 07-24-2007 03:36 PM
on click in popup window throws alert : need to avoid alert of postdata Ganesh ASP .Net 0 06-29-2007 06:51 AM
How to create a form Alert - Not using Alert Boxes Mersh Java 0 03-13-2007 04:14 PM
ALERT: Virus Scam Alert! Toronto Garage Door Company Computer Support 1 11-18-2003 04:16 PM



Advertisments