Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2004, 09:21 AM
Authorized User
 
Join Date: Sep 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open and close windows

I have three forms: showparts.php,showupdate.php and showchange.php.

The goal is for the user to select change in showparts, make a qty change and have that change show back in showparts.

What is happening is when the user clicks on change a new window opens that lets the user change a qty. then submites this to showchange.php. This works fine but when the user clicks close window that window becomes showparts.php with the correct values. What I need to do is have the new window close and have the changes reflected in the origional showparts.php.
The flo is from showparts to showupdate to showchange

following is the code for all three pages. Any and all help would be appreciated.



Selectparts.php
<?php
#####################
#
# set QuoteID cookie to be used throughout the script
#
####################
setcookie("thisQuote","$QuoteID",time()+3600);
global $ItemID,$qty,$thisquote;

?>
<?php
include ("header.php");
?>
<html>
<head>
<script language=javascript>
var detailsWindow;
function showDetails(pageURL)
{
detailsWindow = window.open(pageURL,"partDetails","width=400,heigh t=400");
detailsWindow.focus();
return false;
}

var updateWindow;
function showUpdate(pageURL)
{
window.close;
updateWindow = window.open(pageURL,"partDetails","width=400,heigh t=400");
updateWindow.focus();


return false;
}
</script>
</head>
<body>


<table border=1 align=center width=75%>
<colgroup>
<col width=40%>
<col width=30%>
<col width=5%>
<col width=0*>
<col width=15%>
<?php
$grandtotal=0;
$i=1;


    $result=mysql_query("select * from itemmaster where CatagoryID='$CatagoryID'");
echo "<tr><th colspan=6 align=left>Description</th></tr>";
    while($myrow=mysql_fetch_array($result))
    {

    echo "<form name=$i method=post action=showParts.php>";
?>
<tr>
<td><?php echo "$myrow[Description]";?></td>
<td align=center><input type=button value="Show Details" onclick="return showDetails('showdetail.php?ItemID=<?php echo "$myrow[ItemID]";?>')"></td>
<td align=center> or </td>
<input type=hidden name=flag value=A>
<td align=center><input type=submit name=addDetails value=Add></td>
<input type=hidden name=QuoteID value=<?php echo "$QuoteID";?>><input type=hidden name=PartNum value=<?php echo "$myrow[PartNum]";?>><input type=hidden name=ItemID value=<?php echo "$myrow[ItemID]";?>>
<?php
echo "<td align=center>Qty: <input type=text name=qty size=3></td> </tr>";

echo "<input type=hidden name=CatagoryID value=$CatagoryID></form>";
    $i=$i+1;
    }
echo "</table>";

#########################
# need to create new window
########################
echo "<table align=center border=1 width=75%>";

###################add section#########################
if($flag='A')
{
$sql="insert into quotedetail(QuoteID,ItemID,Qty)values('$QuoteID',' $ItemID','$qty')";
$result=mysql_query($sql);

$result=mysql_query("select * from itemmaster,quotedetail where quotedetail.QuoteID='$thisQuote' and itemmaster.ItemID=quotedetail.ItemID");
echo "<tr><th>&nbsp</th><th>Description</th><th>Part Number</th><th>Qty</th><th>Unit Price</th><th>Extended Price</th></tr>";
    while($myrow=mysql_fetch_array($result))
    {
####################
# get extended total for each part and
# format to currency
###################
    $total=$myrow['Qty']*$myrow['price'];
    $grandtotal=$grandtotal+$total;
    $total=number_format($total,2);
?>
<tr>
<td><input type=button value="Change Qty"
    onclick="return showUpdate('showupdate.php?DetailID=<?php echo "$myrow[DetailID]";?>')" target=self></td>
<?php
echo "<td>$myrow[Description]</td><td>$myrow[PartNum]</td><td>$myrow[Qty]</td><td>\$$myrow[price]</td><td> \$$total </td></tr>";
    }
}
else
{
#########################update section#########################
$result=mysql_query("select * from itemmaster,quotedetail where quotedetail.QuoteID='$thisQuote' and itemmaster.ItemID=quotedetail.ItemID");
echo "<tr><th>&nbsp</th><th>Description</th><th>Part Number</th><th>Qty</th><th>Unit Price</th><th>Extended Price</th></tr>";
    while($myrow=mysql_fetch_array($result))
    {
####################
# get extended total for each part and
# format to currency
###################
    $total=$myrow['Qty']*$myrow['price'];
    $grandtotal=$grandtotal+$total;
    $total=number_format($total,2);
?>
<tr>
<td><input type=button value="Change Qty"
    onclick="return showUpdate('showupdate.php?DetailID=<?php echo "$myrow[DetailID]";?>')"></td>
<?php
echo "<td>$myrow[Description]</td><td>$myrow[PartNum]</td><td>$myrow[Qty]</td><td>\$$myrow[price]</td><td> \$$total </td></tr>";
    }
}


$grandtotal=number_format($grandtotal,2);
echo "<tr><td colspan=5 align=right>Grand total</td><td>\$$grandtotal";

?>

</table>
</body>
</html>

showupdate.php
<?php
include ("header.php");
?>
<html>
<head>
<script language=javascript>
function button_close()
{
window.close();
}
</script>
</head>
<body>
<form name=close method=put action=showchange.php>
<?php
###########################################
# make changes section
##########################################

echo "<table width=75% align=center border=1>";
$result=mysql_query("select * from itemmaster,quotedetail where quotedetail.DetailID='$DetailID' and itemmaster.ItemID=quotedetail.ItemID");
#$result=mysql_query("select * from quotedetail where DetailID='$DetailID'");
while($myrow=mysql_fetch_array($result))
{
echo "<tr><td>Part Number</td><td>$myrow[PartNum]</td></tr>
<tr><td>Description</td><td>$myrow[Description]</td></tr>
<input type=hidden name=DetailID value=$myrow[DetailID]>
<input type=hidden name=changedQty value=1>
<tr><td>Qty.</td><td><input type=text name=Qty value=$myrow[Qty] size=3></td></tr>";
}
echo "<tr><td align=center><input type=submit name=change value=Update></td></tr><table>";
?>

<br><BR>
<input type=submit value="Close Window" onclick="button_close()">
</form>
</body>
</html>

showchange.php
<?php
include("header.php");
?>
<html>
<head>
<script language=javascript>
var detailsWindow;
function button_close()
{

window.close();
window.parent.location=showparts.php;
return false;
}

</script>
</head>
<body>
<form name=changeQty method=post action=showparts.php>
<?php
$sql="update quotedetail set Qty='$Qty' where DetailID='$DetailID'";
$reslt=mysql_query($sql);

echo "<table width=75% align=center border=1>";
$result=mysql_query("select * from itemmaster,quotedetail where quotedetail.DetailID='$DetailID' and itemmaster.ItemID=quotedetail.ItemID");
while($myrow=mysql_fetch_array($result))
{
echo "<tr><td>Part Number</td><td>$myrow[PartNum]</td></tr>
<tr><td>Description</td><td>$myrow[Description]</td></tr>
<input type=hidden name=DetailID value=$myrow[DetailID]>
<input type=hidden name=QuoteID value=$myrow[QuoteID]>
<input type=hidden name=CatagoryID value=$myrow[CatagoryID]>
<input type=hidden name=flag value=U>
<tr><td>Qty.</td><td>$myrow[Qty]</td></tr></table>";
}

?>

<br><BR>

<input type=submit value="Close Window" onclick="window.location='showparts.php' "target="_parent">
</form>
</body>
</html>




 
Old August 17th, 2004, 04:03 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Aside from being very long, this code is very difficult to read.

The question is how do you expect to get help on your logic when the code is cluttered and difficult to follow? Case in point: http://p2p.wrox.com/topic.asp?TOPIC_ID=11967.

Clean it up, cut it down to what's relevant and you'll be more likely to get help.

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail





Similar Threads
Thread Thread Starter Forum Replies Last Post
Tip: How to open/close CDROM automatically crmpicco Javascript How-To 3 April 9th, 2008 05:30 AM
Open/Close Multiple Forms dzisaacs C# 2 August 20th, 2006 05:25 PM
I can open a new window but can't close it camelius ASP.NET 2.0 Basics 0 March 16th, 2006 06:26 AM
open close db mikeuk PHP Databases 3 July 19th, 2004 11:58 AM
Open/Close SQL Connection within every method? flyin ADO.NET 8 May 18th, 2004 07:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.