PDA

View Full Version : Pop-Up Help with Font and Button


DrLongGhost
10-05-2004, 01:55 PM
Here's the code for a function that creates a pop-up window using some previously made calculations. What's the easiest way to make this pop-up window appear in Arial? Also, can someone please tell me why the button I add at the end to close the window causes a JavaScript error? If I can add a <title> tag in the beginning, why can't I use an <input> tag here?

Thanks,
Dan


function display() {
alert('The next screen will display an estimated contract value after withdrawals. The actual amount may be different as a result of contract value changes.');
DispWin = window.open('','NewWin', 'toolbar=no,status=no,width=750,height=400')
message = "<title>Results for CDSC Calculator</title><li><b>CDSC ASSESSED: </b>" + FormatCurrency(totalcdscassessed);
message += "<ul><li><b>NET WITHDRAWAL: </b>" + FormatCurrency(document.form1.withdrawal.value);
message += "<li><b>WITHDRAWAL PLUS CDSC: </b>" + FormatCurrency(grosswithdrawal);
message += "<li><b>EST. CONTRACT VALUE AFTER WITHDRAWAL: </b>" + FormatCurrency(newcontractvalue);
message += "<p>"
for (i=0;i<totalpp;i++){
if (cdscbypremium[i] > 0){
message += "<li><b>Purchase Premium " + (i + 1);
message += ": </b>" + FormatCurrency(premiumchargedcdsc[i]);
message += " of premium charged CDSC at " + round((100 * cdscpercentbypremium[i]));
message += "%<br>"
message +="<li>For a total of " + FormatCurrency(cdscbypremium[i]);
message += " CDSC from premium " + (i + 1);
message += ".<p>";}
else{
message += "<li><b>Purchase Premium " + (i + 1);
message += ": </b> No CDSC Assessed.<p><p>";
}
}
message += "<input TYPE=BUTTON VALUE=Close onClick="closeWindow()">";
DispWin.document.write(message);
}

maxadim
10-06-2004, 12:10 PM
I'm probably missing something glaringly obvious but can't you just do:

function display() {
alert('The next screen will display an estimated contract value after withdrawals. The actual amount may be different as a result of contract value changes.');
DispWin = window.open('','NewWin', 'toolbar=no,status=no,width=750,height=400')
message = "<font face="Arial"><title>Results for CDSC Calculator</title><li><b>CDSC ASSESSED: </b>" + FormatCurrency(totalcdscassessed);
message += "<ul><li><b>NET WITHDRAWAL: </b>" + FormatCurrency(document.form1.withdrawal.value);
message += "<li><b>WITHDRAWAL PLUS CDSC: </b>" + FormatCurrency(grosswithdrawal);
message += "<li><b>EST. CONTRACT VALUE AFTER WITHDRAWAL: </b>" + FormatCurrency(newcontractvalue);
message += "<p>"
for (i=0;i<totalpp;i++){
if (cdscbypremium[i] > 0){
message += "<li><b>Purchase Premium " + (i + 1);
message += ": </b>" + FormatCurrency(premiumchargedcdsc[i]);
message += " of premium charged CDSC at " + round((100 * cdscpercentbypremium[i]));
message += "%<br>"
message +="<li>For a total of " + FormatCurrency(cdscbypremium[i]);
message += " CDSC from premium " + (i + 1);
message += ".<p>";}
else{
message += "<li><b>Purchase Premium " + (i + 1);
message += ": </b> No CDSC Assessed.<p><p></font>";
}
}
message += "<input TYPE=BUTTON VALUE=Close onClick="closeWindow()">";
DispWin.document.write(message);
}

DrLongGhost
10-06-2004, 12:18 PM
When I add the <font> tags as you suggested, it generates an error message. Same thing as with my <input> tag.

This is driving me crazy. I don't see why <title> tags are supported using this method, but not <font> or <input> tags.

I messed around with opening a new html document instead of creating a pop-up, since I could put the <font> tags in the new html file, but I'm not sure how to pass my data variables to this new document. They don't automatically transfer over. Plus, I'm not sure if when I write the data it wouldn't just overwrite the existing HTML anyway.

Does anyone have any other suggestions?

Thanks,
Dan

maxadim
10-06-2004, 01:28 PM
In terms of transferring the variables between the windows I suppose you could use a cookie.

ElectricSheep
10-06-2004, 01:28 PM
The JavaScript interpreter is confused by the way you are using double quotes:

You are using them to quote html attributes and begin and end strings

You need to escape your inner quotes with back slashes like this:

message = "<font face=\"Arial\"> .... ";

message += "<input TYPE=BUTTON VALUE=Close onClick=\"closeWindow()\">";

Now the interpreter will not be confused about where code starts and stops.

You could use properly nested single quotes instead in combination with your double quotes or join the different parts of your strings with the + sign.

HTH

coothead
10-06-2004, 01:45 PM
Hi there DrLongGhost,

further to ElectricSheep's observations, your code could look like this..

function display() {

alert('The next screen will display an estimated contract value after withdrawals. The actual amount may be different as a result of contract value changes.');

DispWin = window.open('','NewWin', 'toolbar=no,status=no,width=750,height=400');

message = "<style type='text/css'>body{font-family:arial}</style><title>Results for CDSC Calculator</title><li><b>CDSC ASSESSED: </b>" + FormatCurrency(totalcdscassessed);
message += "<ul><li><b>NET WITHDRAWAL: </b>" + FormatCurrency(document.form1.withdrawal.value);
message += "<li><b>WITHDRAWAL PLUS CDSC: </b>" + FormatCurrency(grosswithdrawal);
message += "<li><b>EST. CONTRACT VALUE AFTER WITHDRAWAL: </b>" + FormatCurrency(newcontractvalue);
message += "<p>"

for (i=0;i<totalpp;i++) {
if (cdscbypremium[i] > 0) {

message += "<li><b>Purchase Premium " + (i + 1);
message += ": </b>" + "FormatCurrency(premiumchargedcdsc[i])";
message += " of premium charged CDSC at " + Math.round((100 * cdscpercentbypremium[i]));
message += "%<br>"
message +="<li>For a total of " + FormatCurrency(cdscbypremium[i]);
message += " CDSC from premium " + (i + 1);
message += ".<p>";
}
else {

message += "<li><b>Purchase Premium " + (i + 1);
message += ": </b> No CDSC Assessed.<p><p>";
}
}

message += "<input type='button' value='Close' onclick='closeWindow()'>";

DispWin.document.write(message);
}

DrLongGhost
10-06-2004, 02:34 PM
Thanks to everyone for replying!!!

I have now learned my lesson and will remember to nestle my quotes and single quotes in the future.

I went with the <style> tags, since I know <font> is deprecated.

Nestling my quotes worked like a charm, and now I've got my close button added, and my arial font. I also realised I'd forgotten to include "scrollbars" in my features list for the pop-up, so I wasn't getting a scrollbar when I needed it.

Thanks again.