Jump to content

Javascript Help


jhollin1138

Recommended Posts

I feel like a javascript knucklehead here.

 

I am trying to implement the "Modal Dialog Box" script found here h**p://javascript.about.com/b/a/256836.htm. I have been able to get the front end of things working fine; it is the back end of things that isn't working.

 

I am working on a script, in PHP, that is pulling information together and generates one of three different reports. I am using the "Modal Dialog Box" to generate an interface for the user to select which of the reports they want to generate. When the user clicks 'OK', I want to pop-up a new window with their report. Here is my HTML code for the "Modal Dialog Box".

><div id="box" class="dialog">
<form method="post" name="printDialog" action="printWin('./print.php?id=4306&PrintSheet=', 'order');">
 <table align="center">
<tr><td colspan="2">Print Sheet: </td></tr>
<tr><td colspan="2"><input type="radio" name="PrintSheet" value="order" checked="checked" /> Order</td></tr>
<tr><td colspan="2"><input type="radio" name="PrintSheet" value="spec" /> Specification</td></tr>
<tr><td colspan="2"><input type="radio" name="PrintSheet" value="est" /> Estimate</td></tr>
<tr>
  <td> <input type="submit" name="submit" value="OK" onclick="hm('box');" /> </td>
  <td> <input type="reset" value="Cancel" onclick="hm('box');" /> </td>
</tr>
 </table>
</form>
</div>

Here is my javascript that is handling the pop-up window.

>MyPrintWin=null;
function printWin(linkName, printPageDefault) {
 if(MyPrintWin != null) MyPrintWin.close();

 for (var i=0; i < document.printDialog.PrintSheet.length; i++) {
if (document.printDialog.PrintSheet[i].checked) {
  var printPage = document.printDialog.PrintSheet[i].value;
}
 }

 printPageLink = linkName + printPage;

 MyPrintWin = window.open(printPageLink, "printWindow", "width=700,height=500,menubar=no,resizable,toolbar=no,scrollbars");
}

When I click 'OK', the "Modal Dialog Box" is disappearing, but the pop-up isn't showing up.

 

If I change my javascript to:

>MyPrintWin=null;
function printWin(linkName, printPageDefault) {
 if(MyPrintWin != null) MyPrintWin.close();

 printPageLink = linkName + printPageDefault;

 MyPrintWin = window.open(printPageLink, "printWindow", "width=700,height=500,menubar=no,resizable,toolbar=no,scrollbars");
}

Everything works the way I would like, although obviously the value for the radio button is not being used.

 

Am I missing something here?

Link to comment
Share on other sites

Here is an update.

 

I tried the following javascript code, still no luck.

>MyPrintWin=null;
function printWin(linkName, printPageDefault) {
 if(MyPrintWin != null) MyPrintWin.close();

var printPage = printPageDefault;
for (var i=0; i < document.printDialog.PrintSheet.length; i++) {
  if (document.printDialog.PrintSheet[i].checked) {
	printPage = document.printDialog.PrintSheet[i].value;
  }
}

 printPageLink = linkName + printPage;

 MyPrintWin = window.open(printPageLink, "printWindow", "width=700,height=500,menubar=no,resizable,toolbar=no,scrollbars");
}

I also tried using onsubmit instead of action in my html form, no luck.

><div id="box" class="dialog">
<form method="post" name="printDialog" onsubmit="printWin('./print.php?id=4306&PrintSheet=', 'spec');return false;">
 <table align="center">
<tr><td colspan="2">Print Sheet: </td></tr>
<tr><td colspan="2"><input type="radio" name="PrintSheet" value="order" checked="checked" /> Order</td></tr>
<tr><td colspan="2"><input type="radio" name="PrintSheet" value="spec" /> Specification</td></tr>

<tr><td colspan="2"><input type="radio" name="PrintSheet" value="est" /> Estimate</td></tr>
<tr>
  <td> <input type="submit" name="submit" value="OK" onclick="java script:hm('box');" /> </td>
  <td> <input type="reset" value="Cancel" onclick="java script:hm('box');" /> </td>
</tr>
 </table>
</form>
</div>

Any help would be appreciated.

Link to comment
Share on other sites

:) I finally got everything working. The solution came to me when I was giving the kids a bath. Instead of trying to figure out which radio button was picked and set a variable, just set a variable. This is what I came up with for the html section:

><div id="box" class="dialog">
<form method="post" name="printDialog" action="printWin('./print.php?id=4306&PrintSheet=');">
 <table align="center">
<tr><td colspan="2">Print Sheet: </td></tr>
<tr><td colspan="2"><input type="radio" name="PrintSheet" onclick="printPage='order'" /> Order</td></tr>
<tr><td colspan="2"><input type="radio" name="PrintSheet" onclick="printPage='spec'" /> Specification</td></tr>
<tr><td colspan="2"><input type="radio" name="PrintSheet" onclick="printPage='est'" /> Estimate</td></tr>
<tr>
  <td> <input type="submit" name="submit" value="OK" onclick="hm('box');" /> </td>
  <td> <input type="reset" value="Cancel" onclick="hm('box');" /> </td>
</tr>
 </table>
</form>
</div>

Here is the java script:

>MyPrintWin=null;
function printWin(linkName) {
if(MyPrintWin != null) MyPrintWin.close();	
printPageLink = linkName + printPage;
MyPrintWin = window.open(printPageLink, "printWindow", "width=700,height=500,menubar=no,resizable,toolbar=no,scrollbars");
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...