Tue 28 Feb 2006 19:39:20
รบกวนขอสอบถามวิธีทำpopup คือผมมีช่องรับข้อมูลอยู่1ช่องครับ และมีปุ่มaddอยู่ข้างๆ1ปุ่ม เพจที่ใช้คือtest1.php และเพจที่จะทำpopupคือtest2.phpในtest2.phpจะมีข้อมูลคือ
ข้อมูลที่1
ข้อมุลที่2
ข้อมูลที่3
ข้อมูลที่4
เรียงกันลงมา พอกด ปุ่มที่test1.phpให้ popupเล็กๆtest2.phpขึ้นมา พร้อมกับโชข้อมูลด้านในตามข้างบน และพอผมกดข้อมูลแต่ละข้อมุล ให้ข้อมูลนั้นเด้งลงมาที่ช่องรับในtest1.php
รบกวนขอโค้ด ไปศึกษาบ้างครับ
ขอบคุณมากครับ
ในหน้า test1.php นั้นเพียงเพิ่ม
<script language="javascript" type="text/javascript">
function selectValue(id, val){
var obj = (document.all)?document.all[id]:document.getElementById(id);
obj.value = val;
}
</script>
ฟังก์ชั่นนี้เป็นการเซ็ทค่าให้กับ textbox โดยอ้างอิงจาก id ของ object นั้นๆโดยส่งไปเป็น argument ซึ่ง textbox ที่ต้องการรับค่านั้นจึงต้องมีการเพิ่ม attribute id เพื่อไว้อ้างอิงด้วยครับ เช่น
<input type="text" name="text1" id="text1">
จากนั้นใน test2.php นั้นก็เพียงแต่เรียกการทำงานใน test1.php เท่านั้นครับเช่น
<a href="javascript:;" onclick="opener.selectValue('text1', 'ข้อมูลที่1');">ข้อมูลที่ 1</a>
<a href="javascript:;" onclick="opener.selectValue('text1', 'ข้อมูลที่2');">ข้อมูลที่ 2</a>
<a href="javascript:;" onclick="opener.selectValue('text1', 'ข้อมูลที่3');">ข้อมูลที่ 3</a>
<a href="javascript:;" onclick="opener.selectValue('text1', 'ข้อมูลที่4');">ข้อมูลที่ 4</a>
ประมาณนี้ครับ
Mon 6 Mar 2006 11:07:50
โทษนะครับ ผมได้เอาโค้ดไปลองทำดู มะรู้ว่าต้องรันโปรแกรมอย่างไรบ้างนะครับ
คือผมต้องการให้พอรันtest1.phpแล้วพอกดปุ่ม Submitให้test2.phpรันเป็นแบบwindows POPup ขึ้นมาอยู่ข้างๆปุ่ม และในนั้นให้มีข้อมูล
ข้อมูลที่ 1
ข้อมูลที่ 2
ข้อมูลที่ 3
ข้อมูลที่ 4
(ซึ่งข้อมูลเหล่านี้ดึงมาจากฐานข้อมูลmysql) และพอผมเอาเม้าไปคลิ๊กที่popupเลือก ข้อมูลใดข้อมูลนึงในนั้น ให้ข้อมูลที่เราคลิ๊กเลือกลงไปอยู่ ในช่องรับข้อมูลในtest1.phpพร้อมกับปิดpopupอัตโนมัติ
รบกวนด้วยนะครับ
test1.php
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<script language="javascript" type="text/javascript">
function selectValue(id, val){
var obj = (document.all)?document.all[id]:document.getElementById(id);
obj.value = val;
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="form1" method="post" action="">
<input type="text" name="text1" id="text1">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
---------------------------------------
test2.php
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<a href="javascript:;" onclick="opener.selectValue('text1', 'ข้อมูลที่1');">ข้อมูลที่ 1</a><br>
<a href="javascript:;" onclick="opener.selectValue('text1', 'ข้อมูลที่2');">ข้อมูลที่ 2</a><br>
<a href="javascript:;" onclick="opener.selectValue('text1', 'ข้อมูลที่3');">ข้อมูลที่ 3</a><br>
<a href="javascript:;" onclick="opener.selectValue('text1', 'ข้อมูลที่4');">ข้อมูลที่ 4</a>
</body>
รบกวนขอโค้ดตัวอย่างไปศึกษาบ้างนะครับ
ขอบคุณมากครับ
ส่วนใน test2.php นั้นก็เป็นการเรียกใช้งานฟังก์ชั่นที่อยู่ใน test.php เพื่อทำการเซ็ทค่าให้กับ textbox ซึ่งถ้าคุณต้องการประยุกต์ใช้กับ MySQL นั้นก็สามารถทำได้โดย
<?
//make connection
while($row = mysql_fetch_array($res, MYSQL_ASSOC)){
echo "<a href=\"javascript:;\" onclick=\"opener.selectValue('textbox1', ".$row["field_value"].")\">".$row["field_name"]."</a>
}
//close connection
?>
จากตัวอย่างผมสั่งให้เป็นการเซ็ทค่าให้กับ textbox ชื่อ textbox1 ดังนั้นใน test.php จะต้องมี <input type="text" id="textbox1"> อยู่ด้วยครับ
Mon 6 Mar 2006 12:02:35
รบกวนขอโค้ดที่เพจtest1.phpให้พอกดปุ่มแล้วให้เด้งopen windows popup เพจtest2.phpขึ้นมานะครับ
รบกวนด้วยนะครับ
ขอบคุณมากครับ
Mon 6 Mar 2006 15:14:34
รบกวนสอบถามนิดนึงครับ
ผมได้เอาโค้ดที่ให้ไปลองทำดูแล้วครับ ใช้ได้แล้วครับชอบมากๆ จะรบกวนขอเพิ่มอีกนิดนึงนะครับ คืออยากให้พอคลิ๊กข้อมูลที่ต้องการในเพจtest2.phpแล้ว ข้อมูลเด้งลงมาที่ช่องtextboxของเพจtest.phpเรียบร้อยแล้วอยากให้test2.php ปิดอัตโนมัตินะครับ
test1.php--------------------------------
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<script language="javascript" type="text/javascript">
<!--
function selectValue(id, val){
var obj = (document.all)?document.all[id]:document.getElementById(id);
obj.value = val;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="form1" method="post" action="">
<input type="text" id="textbox1">
<input type="button" onclick="MM_openBrWindow('test2.php','','width=200,height=400')" value="Open">
</form>
</body>
test2.php----------------------------------------------------------
อยากให้พอเลือกข้อมูลใดข้อมูลหนึ่งแล้วให้มันปิดอัตโนมัตินะครับ
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<a href="javascript:;" onclick="opener.selectValue('textbox1', 'ข้อมูลที่1');">ข้อมูลที่ 1</a><br>
<a href="javascript:;" onclick="opener.selectValue('textbox1', 'ข้อมูลที่2');">ข้อมูลที่ 2</a><br>
<a href="javascript:;" onclick="opener.selectValue('textbox1', 'ข้อมูลที่3');">ข้อมูลที่ 3</a><br>
<a href="javascript:;" onclick="opener.selectValue('textbox1', 'ข้อมูลที่4');">ข้อมูลที่ 4</a>
</body>
รบกวนขอโค้ดเพิ่ม เพื่อเอาไปเป็นตัวอย่างบ้างนะครับ
ขอบคุณมากครับ
Tue 7 Mar 2006 10:45:54
ขอบคุณมากครับสำหรับโค้ดที่ให้เพิ่มมาด้านบนนี้ จะขอเพิ่มอีกนิดนึงครับ คือผมอยากให้popupที่เกิดขึ้นให้มันเกิดตรงที่ผมกำหนดได้ไหมครับ คืออยากให้พอกดปุ่มopenแล้วให้popupมันโชตรงข้างๆปุ่มเสมอนะครับ คือตอนนี้พอผมกดปุ่มopen popupมันดันไปโชทับปุ่มนะครับ อยากให้มันโชข้างขวาติดกับปุ่มเสมอนะครับ
รบกวนขอโค้ดเวลากดปุ่มopenแล้วให้popupมันมาโชข้างปุ่มด้านขวาติดกับปุ่มเสมอ
ขอบคุณมากครับ
Tue 7 Mar 2006 12:43:02
รบกวนนิดนึงครับคือผมลองเอาtest2.phpไปเปลี่ยนใช้เป็นดึงข้อมูลจากmysqlแล้วมันขึ้นerror รบกวนดูโค้ดให้ทีครับ
Parse error: parse error in c:\appserv\www\รtest\testpopup\test2.php on line 18
test2.php
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?php
$connection = mysql_connect('localhost','root999','1234') or die('Can not connect');
mysql_select_db('DBpopup',$connection);
//make connection
while($row = mysql_fetch_array($res, MYSQL_ASSOC)){
echo "<a href=\"javascript:;\" onclick=\"opener.selectValue('textbox1', ".$row["Testvalue"].")\">".$row["Testname"]."</a>
}
?>
</body>
รบกวนขอโค้ดเวลากดปุ่มopenแล้วให้popupมันมาโชข้างปุ่มด้านขวาติดกับปุ่มเสมอ
ขอบคุณมากครับ
echo "<a href=\"javascript:;\" onclick=\"opener.selectValue('textbox1', ".$row["Testvalue"].")\">".$row["Testname"]."</a>";
ส่วนการให้ popup แสดงผลในตำแหน่งที่ต้องการนั้นให้เพิ่มตำแหน่งของ popup เข้าไปครับ เช่น
<input type="button" value="Open" onclick="window.open('text2.php', 'newwin', width=200, height=400, left=250, top=250')">
Tue 7 Mar 2006 17:21:25
รบกวนนิดนึงครับผมลองเอาโค้ดไปแก้ดูแล้วมันขึ้นerrorแบบนี้นะครับ
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\appserv\www\รtest\testpopup\test2.php on line 13
test2.php----รบกวนดูให้ทีครับมะรู้ว่าผิดตรงไหนนะครับ
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?php
$connection = mysql_connect('localhost','root999','1234') or die('Can not connect');
mysql_select_db('DBpopup',$connection);
//make connection
while($row = mysql_fetch_array($res, MYSQL_ASSOC)){
echo "<a href=\"javascript:;\" onclick=\"opener.selectValue('textbox1', ".$row["Testvalue"].")\">".$row["Testname"]."</a>";
}
?>
</body>
Wed 8 Mar 2006 15:12:26
รบกวนอีกนิดนึงครับ ผมได้เพิ่มquery แล้วครับ แต่มันก็ยังขึ้นerrorตามด้านล่างนี้อยู่เลยครับ
รบกวนดูให้ทีครับว่าผมผิมตรงไหนครับ
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\appserv\www\รtest\testpopup\test2.php on line 15
รบกวนดูโค้ดด้านล่างนี้ทีครับ
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?php
$connection = mysql_connect('localhost','root999','1234') or die('Can not connect');
mysql_select_db('DBpopup',$connection);
$sql = "SELECT * FROM TBpopup";
$result = mysql_query($sql,$connection);
//make connection
while($row = mysql_fetch_array($res, MYSQL_ASSOC)){
echo "<a href=\"javascript:;\" onclick=\"opener.selectValue('textbox1', ".$row["Testvalue"].")\">".$row["Testname"]."</a>";
}
?>
</body>
-------------------------------------------------------------------------------------
ผมใช้โค้ดด้านล่างนี้ลองติดต่อฐานข้อมูลและก็ดึงได้ตามปกติครับ
<?php
$connection = mysql_connect('localhost','root999','1234') or die('Can not connect');
mysql_select_db('DBPopup',$connection);
$sql = "SELECT * FROM TBpopup";
$result = mysql_query($sql,$connection);
while ($records = mysql_fetch_assoc($result)) {
print($records['Testvalue'] . ':' . $records['Testname']);
}
?>
รบกวนด้วยนะครับ
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
//....
ผิดตรงชื่อตัวแปรไม่ตรงกันครับ
Thu 9 Mar 2006 09:43:41
รบกวนนิดนึงครับโค้ดไม่ทำงานนะครับ คือตอนนี้ผมดึงฐานข้อมูลได้แล้ว พอผมรันtest1.phpแล้วกดปุ่มOPENมันก็pupup test2.phpขึ้นมาในtest2.phpก็ดึงฐานข้อมูลขึ้นมาด้วย
แต่พอคลิ๊กเลือกข้อมูลในtest2.phpมันกลับไม่ยอมทำงานใดๆเลยรบกวนช่วยแก้ให้ทีครับ
test1.php-----------------------------------------------
<script language="javascript" type="text/javascript">
<!--
function selectValue(id, val){
var obj = (document.all)?document.all[id]:document.getElementById(id);
obj.value = val;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="form1" method="post" action="">
<input type="text" id="textbox1">
<input type="button" onclick="MM_openBrWindow('test2.php','','width=200,height=80,top=104,left=203')" value="Open">
</form>
</body>
test2.php-----------------------------------------------------------
<?php
$connection = mysql_connect('localhost','root999','1234') or die('Can not connect');
mysql_select_db('DBpopup',$connection);
$sql = "SELECT * FROM TBpopup";
$result = mysql_query($sql,$connection);
//make connection
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
// echo "<a href=\"javascript:;\" onclick=\"opener.selectValue('textbox1', ".$row["Testvalue"].")\">".$row["Testname"]."</a>","<br>";
echo "<a href=\"javascript:;\" onclick=\"opener.selectValue('textbox1', ".$row["Testvalue"].")\"window.close();\">".$row["Testname"]."</a>","<br>";
}
?>
------------------------------------------------------------------------------------------
รบกวนด้วยนะครับ
Thu 9 Mar 2006 12:02:00
ขอบคุณมากครับ
Sat 18 Mar 2006 18:31:54
รบกวนขอสอบถามเพิ่มครับ คือพอคลิ๊กปุ่มopenที่test1.phpแล้วpopupหน้าtest2.phpก็จะเด้งขึ้นมา พร้อมกับข้อมูลด้านในพอผมกดเลือกที่ข้อมูลมันก็จะลงมาอยู่ในtextboxในtest1.php ที่นี้คือ มีวิธีที่จะเพิ่มให้มันสามารถแดรกเม้าที่ข้อมูลแถวที่ต้องการในtest2.phpแล้วลากลงมาในtextboxของtest1.phpไหมครับ (ลากข้อมูลโดยใช้เม้าคลุมข้อมูลที่ต้องการแล้วแดรกเม้าลากลงมาในtestboxของtest1.php) (โดยให้เพิ่มความสามารถเพิ่มเติมเข้าไปนะครับ)
รบกวนขอโค้ดเพิ่มบ้างครับ
-----------------------------------------------------------------------------
test1.php
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<script language="javascript" type="text/javascript">
<!--
function selectValue(id, val){
var obj = (document.all)?document.all[id]:document.getElementById(id);
obj.value = val;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="form1" method="post" action="">
<input type="text" id="textbox1">
<input type="button" onclick="MM_openBrWindow('test2.php','','width=200,height=80,top=104,left=203')" value="Open">
</form>
</body>
-----------------------------------------------------------------------------------------
test2.php
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?php
$connection = mysql_connect('localhost','root999','1234') or die('Can not connect');
mysql_select_db('DBpopup',$connection);
$sql = "SELECT * FROM TBpopup";
$result = mysql_query($sql,$connection);
//make connection
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo "<a href=\"javascript:;\" onclick=\"opener.selectValue('textbox1', '".$row["Testvalue"]."');window.close();\">".$row["Testname"]."</a>","<br>";
}
?>
</body>
รบกวนด้วยนะครับ
ขอบคุณมากครับ
Wed 22 Mar 2006 08:17:51
มีวิธีที่จะเพิ่มให้มันสามารถแดรกเม้าที่ข้อมูลแถวที่ต้องการในtest2.phpแล้วลากลงมาในtextboxของtest1.phpไหมครับ (ลากข้อมูลโดยใช้เม้าคลุมข้อมูลที่ต้องการแล้วแดรกเม้าลากลงมาในtestboxของtest1.php) (โดยให้เพิ่มความสามารถเพิ่มเติมเข้าไปนะครับ)
รบกวนขอโค้ดเพิ่มบ้างครับ

















