|
|
|
JS Pop-up ยกเลิกการแสดงข้อมูลที่เลือกแล้ว จะทำอย่างไร |
|
|
|
|
|
|
|
ผมได้แปลงบทความ https://www.thaicreate.com/community/javascript-passing-send-data-popup-to-main-page.html
โดยมี code ดังนี้
getMain1.php
<?php
session_start();
include("config/config.php");
$dbhandle = mysql_connect($host,$user,$pass);
mysql_select_db($db, $dbhandle);
mysql_query("set names UTF8");
if($_SESSION["USERID"]==""){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">\n";
exit();
}
if ($_SESSION['GID']!=3){
exit();
}
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="8"><img src="images/Untitled-1.jpg" width="100%" height="90" /></td>
</tr>
</table>
</form>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
text-align: center;
}
#form2 {
font-weight: bold;
text-align: center;
}
a:link {
color:#6699cc;
text-decoration:none;
}
a:hover {
color:#f60051;
text-decoration:underline;
}
a:visited {
color:#D6D6D6;
text-decoration:none;
}
</style>
</head>
<?
mysql_connect("localhost","root","1234") or die("Error Connect to Database");
mysql_query("set names UTF8");
mysql_select_db("stockpart");
$strSQL = "SELECT * FROM product";
$objQuery = mysql_query($strSQL);
?>
<script language="javascript">
function OpenPopup(intLine)
{
window.open('getData.php?Line='+intLine,'myPopup','width=650,height=200,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
}
/*function CreateSelectOption(ele)
{
var objSelect = document.getElementById(ele);
var Item = new Option("", "");
objSelect.options[objSelect.length] = Item;
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
var Item = new Option("<?=$objResult["CountryName"];?>", "<?=$objResult["CountryCode"];?>");
objSelect.options[objSelect.length] = Item;
<?
}
?>
}*/
function CreateNewRow()
{
var intLine = parseInt(document.frmMain.hdnMaxLine.value);
intLine++;
var theTable = document.getElementById("tbExp");
var newRow = theTable.insertRow(theTable.rows.length)
newRow.id = newRow.uniqueID
var newCell;
//*** Column No ***//
newCell = newRow.insertCell(0);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center>"+intLine+"</center>";
//*** Column pro_name ***//
newCell = newRow.insertCell(1);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"25\" NAME=\"txt_pro_name_"+intLine+"\" ID=\"txt_pro_name_"+intLine+"\" VALUE=\"\"></center>";
//*** Column value จำนวนที่มี ***//
/*newCell = newRow.insertCell(2);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"10\" NAME=\"txt_sum_pro_"+intLine+"\" ID=\"txt_sum_pro_"+intLine+"\" VALUE=\"\"></center>";
*/
//*** Column value จำนวนที่รับ ***//
newCell = newRow.insertCell(2);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"10\" NAME=\"txt_sum_proNew_"+intLine+"\" ID=\"txt_sum_proNew_"+intLine+"\" VALUE=\"\"></center>";
//*** Column unit_id หน่วยสินค้า ***//
newCell = newRow.insertCell(3);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"10\" NAME=\"txt_unit_name_"+intLine+"\" ID=\"txt_unit_name_"+intLine+"\" VALUE=\"\"></center>";
//*** Create Option ***//
//CreateSelectOption("txt_unit_id_"+intLine)
//*** Column price ***//
newCell = newRow.insertCell(4);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txt_in_price_pro_"+intLine+"\" ID=\"txt_in_price_pro_"+intLine+"\" VALUE=\"\"></center>";
//*** Column จำนวนเงิน ***//
newCell = newRow.insertCell(5);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtVol3_"+intLine+"\" ID=\"txtVol3_"+intLine+"\" VALUE=\"\"></center>";
//... button ปุ่มกดเพิ่มรายการ//
newCell = newRow.insertCell(6);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
//newCell.setAttribute("OnClick", "OpenPopup('"+intLine+"')");
newCell.innerHTML = "<center><INPUT TYPE=\"BUTTON\" NAME=\"btnPopup_"+intLine+"\" ID=\"btnPopup_"+intLine+"\" VALUE=\"...\" OnClick=\"OpenPopup('"+intLine+"')\"></center>";
document.frmMain.hdnMaxLine.value = intLine;
}
function fncCal()
{
intLine = parseInt(document.frmMain.hdnMaxLine.value);
var total = 0;
var sum = 0;
for(i=1;i<=parseInt(intLine);i++)
{
total = parseInt(eval("document.frmMain.txt_sum_proNew_"+i+".value")) * parseInt(eval("document.frmMain.txt_in_price_pro_"+i+".value"))
eval("document.frmMain.txtVol3_"+i+".value="+total);
sum = total + sum;
document.frmMain.txtSum.value=sum;
//alert(sum);
}
}
function RemoveRow()
{
intLine = parseInt(document.frmMain.hdnMaxLine.value);
if(parseInt(intLine) > 0)
{
theTable = document.getElementById("tbExp");
theTableBody = theTable.tBodies[0];
theTableBody.deleteRow(intLine);
intLine--;
document.frmMain.hdnMaxLine.value = intLine;
}
}
</script>
<body background="images/bg1.jpg" bgproperties="fixed" OnLoad="CreateNewRow();">
<form name="frmMain" method="post" action="readData.php">
<table align="center" width="800" border="1" cellspacing="0" id="tbExp">
<tr><th bgcolor="#7F7F7F" colspan="7">รายการรับสินค้า</th></tr>
<tr>
<td bgcolor="#CCCCCC"><div align="center">No </div></td>
<td bgcolor="#CCCCCC"><div align="center">ชื่อสินค้า </div></td>
<td bgcolor="#CCCCCC"><div align="center">จำนวนที่รับ </div></td>
<td bgcolor="#CCCCCC"><div align="center">หน่วยนับสินค้า </div></td>
<td bgcolor="#CCCCCC"><div align="center">ราคาต่อหน่วย </div></td>
<td bgcolor="#CCCCCC"><div align="center">จำนวนเงิน </div></td>
<td bgcolor="#CCCCCC"><div align="center">เพิ่มรายการ </div></td>
</tr>
</table>
<br/>
<table align="center" width="800" border="0" cellspacing="0" id="tbExp">
<tr>
<td><div align="right">จำนวนเงินทั้งหมด : <input name="txtSum" id="txtSum" type="text"> บาท</div></td>
</tr>
</table>
<br/>
<input type="hidden" name="hdnMaxLine" value="0">
<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
<input name="btnCal" type="button" value="คำนวณใหม่" OnClick="fncCal();">
<input type="submit" name="btnSubmit" value="แสดงใบรับสินค้า">
</form>
</body>
</html>
getData.php
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
a:link {
color:#000000;
text-decoration:none;
}
a:hover {
color:#000000;
background-color:yellow;
}
a:visited {
color:#000000;
text-decoration:none;
}
</style>
</head>
<script language="javascript">
function selData(intLine,pro_name,unit_name,in_price_pro)
{
var spro_name = self.opener.document.getElementById("txt_pro_name_" +intLine);
spro_name.value = pro_name;
/*var ssum_pro = self.opener.document.getElementById("txt_sum_pro_" +intLine);
ssum_pro.value = sum_pro;
*/
/*var sunit_id = self.opener.document.getElementById("txt_unit_id_" +intLine);
sunit_id.value = unit_id;
*/
var sunit_name = self.opener.document.getElementById("txt_unit_name_" +intLine);
sunit_name.value = unit_name;
var sin_price_pro = self.opener.document.getElementById("txt_in_price_pro_" +intLine);
sin_price_pro.value = in_price_pro;
window.close();
}
</script>
<body bgcolor="#EBEBEB">
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
mysql_query("set names UTF8");
$objDB = mysql_select_db("stockpart");
$strSQL = "SELECT * FROM product";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1" align="center" cellspacing="0">
<tr>
<th bgcolor="#CCCCCC" width="100"><div align="center">ชื่อสินค้า </div></th>
<th bgcolor="#CCCCCC" width="120"><div align="center">จำนวนที่เหลือ </div></th>
<th bgcolor="#CCCCCC" width="130"><div align="center">หน่วยนับสินค้า </div></th>
<th bgcolor="#CCCCCC" width="110"><div align="center">ราคาต่อหน่วย </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
$id = $objResult["unit_id"];
$sql="select unit_name from unit where unit_id = $id";
$objQuery2 = mysql_query($sql);
$objResult2 = mysql_fetch_array($objQuery2);
?>
<tr>
<td><div align="center"><a href="#" OnClick="selData('<?=$_GET["Line"];?>','<?=$objResult["pro_name"];?>','<?=$objResult2["unit_name"];?>','<?=$objResult["in_price_pro"];?>');">
<?=$objResult["pro_name"];?>
</a></div></td>
<td><div align="center"><?=$objResult["sum_pro"];?></div></td>
<td><div align="center"><?=$objResult2["unit_name"];?>
<!-- <select name=<?=$objResult["unit_id"];?> id=<?=$objResult["unit_id"];?>>
<option>--เลือก--</option>
<?
$sql="select * from unit order by unit_name";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result)){
if ($objResult["unit_id"]==$row[0]) { $unit_sel = 'selected="selected"'; } else { $unit_sel = ''; }
echo "<option value='$row[0]'".$unit_sel.">$row[1]</option>";
}
?>
</select> -->
</div>
</td>
<td><div align="center"><?=$objResult["in_price_pro"];?></div></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>
อยากให้เมื่อเราเลือกข้อมูลใน pop-up แล้ว เมื่อเพิ่มแถวใหม่จะไม่แสดงข้อมูลที่เลือกใน pop-up แล้วอ่ะครับ
Tag : JavaScript
|
|
|
|
|
|
Date :
2013-08-28 23:35:26 |
By :
psks |
View :
1168 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังไงหว๋า ตัวอย่างก็ชัดเจนแล้วน่ะครับ
|
|
|
|
|
Date :
2013-08-29 06:00:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|