จากบทความการทำ Move Option List/ListMenu เทคนิคการทำเพิ่ม/ลบ/ย้าย Option Items ใน List Menu ถ้าไม่เอา head body มันไม่แก้ให้ค่ะ และจากกระทู้เก่าค่ะ
จากบทความ https://www.thaicreate.com/community/javascript-move-option-list.html
ตอนนี้ ติดปัญหาคือ Page php ที่ทำฟอร์มนั้น ต้องไม่ใช่ html head body พวกนี้ เพราะหน้านี้จะถูกดึงไปใช้ในกรอบ content ทำให้เขียนโดดๆขึ้นมาเลยค่ะ
เวลาเอาไปใช้จริงๆ เรียก content ส่วนของหน้านี้ขึ้นมา แสดงข้อมูลปกติ แต่แอดข้อมูลไม่ได้ค่ะ
menu.php โค้ดของหน้านี้
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administrator Area</title>
<LINK href="../stylecssno1.css" type=text/css rel=stylesheet>
<script type="text/javascript" src="dynifs.js"></script>
<link rel="../stylesheet" type="text/css" media="all" href="dropmenu.css" />
<script type="text/javascript" src="dropmenu.js"></script>
<link rel="stylesheet" href="tinybox/style.css" />
<script type="text/javascript" src="tinybox/packed.js"></script>
<script LANGUAGE="JavaScript">
function pu(a,b)
{
window.open('content_edit_2.asp?content='+a+'&lang='+b,'name','height=630,width=800,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes');
//window.showModalDialog('content_edit_2.asp?content='+a+'&lang='+b,'name','dialogWidth:800px;dialogHeight: 500px;center: yes;resize: no;status: no;help:no');
//TINY.box.show('content_edit_2.asp?content='+a+'&lang='+b,1,800,500,1)
}
function tp(a,lnk,tar)
{
//var hd = 'b'+hd;
//alert(this);
//document.getElementById(s).className = "btnactive";
if (tar == 'top' )
{parent.location.href = lnk}
else if (tar == 'nw' )
{window.open(lnk,'mywindow');}
else
{
resethd();
parent.myiframe.location.href = lnk;
a.className = "btnactive";}
}
function trans(){
tt= document.getElementById('rep').value;
window.open('q_rpt_trans.asp?ref='+tt,'w1d', config='x=1,height=500,width=700,toolbar=no,menubar=no,scrollbars=yes,resizable=no,directories=no,status=no,left=120,top=90');
}
function trans2(){
tt= document.getElementById('ref').value;
window.open('trans.asp?ref='+tt,'myiframe');
}
</script>
</head>
<body> <center>
<table width="801" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="153" height="63" align="center">.. Logo ..</td>
<td width="639" valign="middle">
Home | About | Country | Contact</td>
</tr>
<tr>
<td height="435" valign="top"><p>Menu 1</p>
<p>Menu 2</p>
<p>Menu 3</p></td>
<td valign="top">
... Content ...
</td>
</tr>
</table>
<br />
<script language="">
function resethd(){
var totalhd = 20 + 1;
for(var i = 1; i <= totalhd ; i++)
{
hdtemp = 'b'+i;
hdobject = document.getElementById(hdtemp);
if (hdobject){
//alert (document.getElementById(hdtemp));
hdobject.className = 'btn';
}
}
}
</script>
</center>
</body>
</html>
ตอนนี้ Content ที่ต้องการนำมาใส่ เกี่ยวกับ Country moveoption listmenu ค่ะ
ไฟล์ addItem.php เขียนโดยไม่มี head body เมื่อนำมาใช้งาน มันใช้ไม่ได้น่ะคะ
Code (PHP)
<script>removeAllItem()</scirpt>
<script language="JavaScript">
function MoveOption(objSourceElement, objTargetElement) {
var aryTempSourceOptions = new Array();
var x = 0;
for (var i = 0; i < objSourceElement.length; i++) {
if (objSourceElement.options[i].selected) {
var intTargetLen = objTargetElement.length++;
objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
}
else {
var objTempValues = new Object();
objTempValues.text = objSourceElement.options[i].text;
objTempValues.value = objSourceElement.options[i].value;
aryTempSourceOptions[x] = objTempValues;
x++;
}
}
objSourceElement.length = aryTempSourceOptions.length;
for (var i = 0; i < aryTempSourceOptions.length; i++) {
objSourceElement.options[i].text = aryTempSourceOptions[i].text;
objSourceElement.options[i].value = aryTempSourceOptions[i].value;
objSourceElement.options[i].selected = false;
}
}
function checkAllItems()
{
for (var i = 0; i < frmMain.ddlLeft.length; i++) {
frmMain.ddlLeft.options[i].selected = true;
}
for (var i = 0; i < frmMain.ddlRight.length; i++) {
frmMain.ddlRight.options[i].selected = true;
}
}
function removeAllItems()
{
for (var i = 0; i < frmMain.ddlLeft.length; i++) {
frmMain.ddlLeft.options[i].selected = false;
}
for (var i = 0; i < frmMain.ddlRight.length; i++) {
frmMain.ddlRight.options[i].selected = false;
}
}
</script>
<form name="frmMain" action="addItem2.php" method="post" onSubmit="checkAllItems();">
<table width="500" border="0" align="center">
<tr>
<td width="90" valign="top">Country:</td>
<td><table width="490" border="0" cellspacing="4" cellpadding="0">
<tr>
<td><select name="ddlLeft[]" id="ddlLeft" size="12" multiple style="width: 230px;">
<OPTION VALUE="Christmas Island">Christmas Island</OPTION>
<OPTION VALUE="Cocos (Keeling) Islands">Cocos (Keeling) Islands</OPTION>
<OPTION VALUE="Colombia">Colombia</OPTION>
<OPTION VALUE="Comoros">Comoros</OPTION>
<OPTION VALUE="Congo">Congo</OPTION>
<OPTION VALUE="Cook Islands">Cook Islands</OPTION>
<OPTION VALUE="Costa Rica">Costa Rica</OPTION>
<OPTION VALUE="Cuba">Cuba</OPTION>
<OPTION VALUE="Djibouti">Djibouti</OPTION>
<OPTION VALUE="Dominica">Dominica</OPTION>
<OPTION VALUE="Dominican Republic">Dominican Republic</OPTION>
<OPTION VALUE="East Timor">East Timor</OPTION>
<OPTION VALUE="Ecuador">Ecuador</OPTION>
<OPTION VALUE="El Salvador">El Salvador</OPTION>
<OPTION VALUE="Equatorial Guinea">Equatorial Guinea</OPTION>
<OPTION VALUE="Eritrea">Eritrea</OPTION>
<OPTION VALUE="Ethiopia">Ethiopia</OPTION>
<OPTION VALUE="Falkland Islands">Falkland Islands</OPTION>
<OPTION VALUE="Faroe Islands">Faroe Islands</OPTION>
<OPTION VALUE="Fiji">Fiji</OPTION>
<OPTION VALUE="French Guiana">French Guiana</OPTION>
<OPTION VALUE="French Polynesia">French Polynesia</OPTION>
</select></td>
<td width="30"><div align="center">
<input type="button" name="MoveRight" value=">> " style="width: 30px;" onClick="MoveOption(this.form.ddlLeft, this.form.ddlRight)">
<br>
<br>
<input type="button" name="MoveLeft" value="<<" style="width: 30px;" onClick="MoveOption(this.form.ddlRight, this.form.ddlLeft)">
</div></td>
<td><select name="ddlRight[]" id="ddlRight" size="12" multiple style="width: 230px;">
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td align="center"><input name="btnSubmit" type="submit" id="btnSubmit" value="Submit"></td>
</tr>
</table>
</form>
เมื่อมีการรันหน้าทั้งหมดให้เรียกงาน
ไฟล์ addItem.php จะเข้ามาอยู่ใน menu.php
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administrator Area</title>
<LINK href="../stylecssno1.css" type=text/css rel=stylesheet>
<script type="text/javascript" src="dynifs.js"></script>
<link rel="../stylesheet" type="text/css" media="all" href="dropmenu.css" />
<script type="text/javascript" src="dropmenu.js"></script>
<link rel="stylesheet" href="tinybox/style.css" />
<script type="text/javascript" src="tinybox/packed.js"></script>
<script LANGUAGE="JavaScript">
function pu(a,b)
{
window.open('content_edit_2.asp?content='+a+'&lang='+b,'name','height=630,width=800,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes');
//window.showModalDialog('content_edit_2.asp?content='+a+'&lang='+b,'name','dialogWidth:800px;dialogHeight: 500px;center: yes;resize: no;status: no;help:no');
//TINY.box.show('content_edit_2.asp?content='+a+'&lang='+b,1,800,500,1)
}
function tp(a,lnk,tar)
{
//var hd = 'b'+hd;
//alert(this);
//document.getElementById(s).className = "btnactive";
if (tar == 'top' )
{parent.location.href = lnk}
else if (tar == 'nw' )
{window.open(lnk,'mywindow');}
else
{
resethd();
parent.myiframe.location.href = lnk;
a.className = "btnactive";}
}
function trans(){
tt= document.getElementById('rep').value;
window.open('q_rpt_trans.asp?ref='+tt,'w1d', config='x=1,height=500,width=700,toolbar=no,menubar=no,scrollbars=yes,resizable=no,directories=no,status=no,left=120,top=90');
}
function trans2(){
tt= document.getElementById('ref').value;
window.open('trans.asp?ref='+tt,'myiframe');
}
</script>
</head>
<body> <center>
<table width="801" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="153" height="63" align="center">.. Logo ..</td>
<td width="639" valign="middle">
Home | About | Country | Contact</td>
</tr>
<tr>
<td height="435" valign="top"><p>Menu 1</p>
<p>Menu 2</p>
<p>Menu 3</p></td>
<td valign="top">
<script>removeAllItems()</script>
<script language="JavaScript">
function MoveOption(objSourceElement, objTargetElement) {
var aryTempSourceOptions = new Array();
var x = 0;
for (var i = 0; i < objSourceElement.length; i++) {
if (objSourceElement.options[i].selected) {
var intTargetLen = objTargetElement.length++;
objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
}
else {
var objTempValues = new Object();
objTempValues.text = objSourceElement.options[i].text;
objTempValues.value = objSourceElement.options[i].value;
aryTempSourceOptions[x] = objTempValues;
x++;
}
}
objSourceElement.length = aryTempSourceOptions.length;
for (var i = 0; i < aryTempSourceOptions.length; i++) {
objSourceElement.options[i].text = aryTempSourceOptions[i].text;
objSourceElement.options[i].value = aryTempSourceOptions[i].value;
objSourceElement.options[i].selected = false;
}
}
function checkAllItems()
{
for (var i = 0; i < frmMain.ddlLeft.length; i++) {
frmMain.ddlLeft.options[i].selected = true;
}
for (var i = 0; i < frmMain.ddlRight.length; i++) {
frmMain.ddlRight.options[i].selected = true;
}
}
function removeAllItems()
{
for (var i = 0; i < frmMain.ddlLeft.length; i++) {
frmMain.ddlLeft.options[i].selected = false;
}
for (var i = 0; i < frmMain.ddlRight.length; i++) {
frmMain.ddlRight.options[i].selected = false;
}
}
</script>
<form name="frmMain" action="addItem2.php" method="post" onSubmit="checkAllItems();">
<table width="500" border="0" align="center">
<tr>
<td width="90" valign="top">Country:</td>
<td><table width="490" border="0" cellspacing="4" cellpadding="0">
<tr>
<td><select name="ddlLeft[]" id="ddlLeft" size="12" multiple style="width: 230px;">
<OPTION VALUE="Christmas Island">Christmas Island</OPTION>
<OPTION VALUE="Cocos (Keeling) Islands">Cocos (Keeling) Islands</OPTION>
<OPTION VALUE="Colombia">Colombia</OPTION>
<OPTION VALUE="Comoros">Comoros</OPTION>
<OPTION VALUE="Congo">Congo</OPTION>
<OPTION VALUE="Cook Islands">Cook Islands</OPTION>
<OPTION VALUE="Costa Rica">Costa Rica</OPTION>
<OPTION VALUE="Cuba">Cuba</OPTION>
<OPTION VALUE="Djibouti">Djibouti</OPTION>
<OPTION VALUE="Dominica">Dominica</OPTION>
<OPTION VALUE="Dominican Republic">Dominican Republic</OPTION>
<OPTION VALUE="East Timor">East Timor</OPTION>
<OPTION VALUE="Ecuador">Ecuador</OPTION>
<OPTION VALUE="El Salvador">El Salvador</OPTION>
<OPTION VALUE="Equatorial Guinea">Equatorial Guinea</OPTION>
<OPTION VALUE="Eritrea">Eritrea</OPTION>
<OPTION VALUE="Ethiopia">Ethiopia</OPTION>
<OPTION VALUE="Falkland Islands">Falkland Islands</OPTION>
<OPTION VALUE="Faroe Islands">Faroe Islands</OPTION>
<OPTION VALUE="Fiji">Fiji</OPTION>
<OPTION VALUE="French Guiana">French Guiana</OPTION>
<OPTION VALUE="French Polynesia">French Polynesia</OPTION>
</select></td>
<td width="30"><div align="center">
<input type="button" name="MoveRight" value=">> " style="width: 30px;" onClick="MoveOption(this.form.ddlLeft, this.form.ddlRight)">
<br>
<br>
<input type="button" name="MoveLeft" value="<<" style="width: 30px;" onClick="MoveOption(this.form.ddlRight, this.form.ddlLeft)">
</div></td>
<td><select name="ddlRight[]" id="ddlRight" size="12" multiple style="width: 230px;">
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td align="center"><input name="btnSubmit" type="submit" id="btnSubmit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<br />
<script language="">
function resethd(){
var totalhd = 20 + 1;
for(var i = 1; i <= totalhd ; i++)
{
hdtemp = 'b'+i;
hdobject = document.getElementById(hdtemp);
if (hdobject){
//alert (document.getElementById(hdtemp));
hdobject.className = 'btn';
}
}
}
</script>
</center>
</body>
</html>
addItem2.php
Code (PHP)
for($i=0;$i<=count($_POST["ddlRight"]);$i++)
{
if($_POST["ddlRight"][$i] != "")
{
$strSQL = "INSERT INTO test ";
$strSQL .="(Country) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["ddlRight"][$i]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
}
}
มันจะไม่ขึ้นแสดงซักประเทศที่เราเลือกเลยค่ะ ลอง echo $_POST["ddlRight"][$i] ได้ค่าว่าง
มีวิธีแก้มั๊ยคะ ที่จะไม่ใช่ head body ในส่วนของบทความนี้ ถ้าเกิดต้องไม่ใช้จริงๆ
เพราะจากบทความ มีการใช้ head body onload ค่ะTag : PHP, MySQL
Date :
2011-06-10 09:55:40
By :
pink22
View :
1040
Reply :
1
จะมีใครช่วยตอบบ้างมั๊ยยยคะ
Date :
2011-06-12 15:13:33
By :
pink22
Load balance : Server 02