473,805 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New Window Instead of Alert Box?

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="Showto tal()" value="TOTAL">

Showtotal():

function Showtotal(){
var answerText = "What is the
total?\n------------------------------------\n";
for(i=1;i<=5;i+ +){
answerText=answ erText+"\nQuest ion :"+i+"\n";
if(ans[i]!=yourAns[i]){
answerText=answ erText+"\nThe correct answer was
"+ans[i]+"\n"+explainAn swer[i]+"\n";
}
else{
answerText=answ erText+" \nCorrect! \n";
score++;
}
}
[some code snipped]
alert(answerTex t); <---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.writ e('<html><head> <title>Choice </title></head><body><pre >'+answerText+' </pre></body></html>');
w.document.clos e();
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.
Jul 23 '05 #1
1 1710
In article <e2************ **************@ posting.google. com>,
tm******@splice d.com 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.docum ent)
h_window = window.open("", "Choice","heigh t=300,width=
300,scrollbars= yes,resizable=y es");
var doc = h_window.docume nt;
doc.open();
doc.writeln("<h tml><head><titl e>Choice</title>");
doc.writeln("</head><body>");
doc.writeln("<p re>" + answerText + "</pre>");
doc.writeln("</body></html>");
doc.close();
h_window.focus( );
return;
}

Change the line of code in ShowTotal() from
alert(answerTex t);
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

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
14741
by: Scott | last post by:
I'm new to ASP, but I've been programming in VB for several years, and I'm having a few issues with this ASP enhancement I'm working on. I've found ASP to be a lot different than what I'm use to in VB. I've created an ASP interface where a user can select an email group that populates a listbox with those email addresses. If a user sees an email in that list that they do not want then they can remove it by clinking the Delete button...
9
4994
by: Justin Koivisto | last post by:
Is there a way to create an alert-like message box that uses a custom image? Basically, I want to replace the default ! image with something else. -- Justin Koivisto - spam@koivi.com PHP POSTERS: Please use comp.lang.php for PHP related questions, alt.php* groups are not recommended.
5
7547
by: spam_me_ not | last post by:
I already understand that one cannot disable a browser's forward and back functions. This is a situation where I have code working in Mozilla V1.6 and would like something similar for Opera and IE. I link within a page and display individual divisions of that page, manipulating their visibility and display styles with an onClick function. As long as I explicitly click a link to progress, it works with browsers I've tried.
2
3296
by: Terry | last post by:
anyone know how to pop up a confirm window with (Y) & (N)?? I want to pop up a "Do you want to continue?" message box (javascript only, can't use vbscript) with (Y) & (N). when click (N), then close the current window. If click (Y), then back to server side to continue. Is it possible?? Thanks a lot.
3
8136
by: Russell | last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull. I have a modal dialog that is an IFrame. The IFrame contains another window - which contains the appropriate title. I am trying to change the title of the IFrame window to be that of the contained window title. If I uncomment the alert statement below - the title change works. Comment out the alert - and - no title change.
8
1647
by: mike | last post by:
I have a parent window where I open a child window. In that child window I have some js that creates a row in the parent window, it looks like: if ( self.opener.document.update ) { var actTable = self.opener.document.getElementById("Action_Table"); myTR = self.opener.document.createElement("TR");
3
10739
by: alison | last post by:
I am trying to redirect the parent page when the user clicks an html button in an aspx page by using the javascript: window.opener.location.href="EditOrders.aspx"; This works fine on IE for windows or Firefox, however on IE for Mac or Safari on Mac, it doesn't work. If I enable script errors on IE for Mac, I get: 'window.opener.location' is not an object. Any ideas on how to get this to work on Mac browsers? Thanks!
26
5694
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized several parts of the DOM, but this does not include the window object. Thank you
24
8238
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and seems to have a (tiny) amount overhead since window itself points to the global object, hence, a circular reference. (From everything I am reading, window is just a REFERENCE back to the global object, as opposed to a separate object.)
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.