 |
ดึงข้อมูลนำมาโชว์ใน ListMenu และ Set Default Selected แบบ Multiple ไม่ได้เหรอครับ |
|
 |
|
|
 |
 |
|
ตกลง javascript อันนี้มันใช้ได้กับ multiple ป่าวคับ
|
 |
 |
 |
 |
Date :
2011-08-20 21:41:08 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะทำอะไรครับ 
|
 |
 |
 |
 |
Date :
2011-08-20 21:44:17 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะคืนค่า Default อะครับ ที่พี่วินเคยเขียนให้ พอดีทำได้กับ Dependent แล้ว เลยเอามาลองกับ Listmenu แบบ multiple ดูคับ
|
 |
 |
 |
 |
Date :
2011-08-20 21:57:15 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยดูโค๊ดทีนะครับว่าได้ไหม ถ้าได้ควรแก้ตรงไหนครับ
|
 |
 |
 |
 |
Date :
2011-08-21 09:09:48 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Capture หน้าจอรูปมาให้หน่อยครับ 
|
 |
 |
 |
 |
Date :
2011-08-21 09:10:42 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

เวลากดปุ่มแก้ไขข้อมูลอยากให้ข้อมูลมาโชว์ที่ Listmenu แบบ multiple เหมือนเดิมอะครับ
|
 |
 |
 |
 |
Date :
2011-08-21 09:36:59 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลงรูปแล้วนะครับ ให้ข้อมูลที่เคย add ในช่อง listmenu ขึ้นมาอะครับ ตอนกดแก้ไข
|
 |
 |
 |
 |
Date :
2011-08-21 16:04:45 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แป๊บครับ กำลังเขียนให้ครับ 
|
 |
 |
 |
 |
Date :
2011-08-21 16:06:44 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (JavaScript)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body OnLoad="setDefault();">
<script language="JavaScript">
function setDefault()
{
var itemSel=document.frmMain.lmName3;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="a")
{
itemSel.options[x].selected = true;
break;
}
}
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="c")
{
itemSel.options[x].selected = true;
break;
}
}
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="e")
{
itemSel.options[x].selected = true;
break;
}
}
}
</script>
<form action="PageListMenu2.php" method="post" name="frmMain">
List Menu 3<br>
<select name="lmName3[]" id="lmName3" size="5" multiple>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
<option value="f">f</option>
<option value="g">g</option>
</select><br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
Screenshot

Go to : PHP Select/Listmenu
|
 |
 |
 |
 |
Date :
2011-08-21 16:44:35 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ไม่ได้ยังไงบอกด้วยครับ ไม่เข้าใจถามเพิ่มได้ครับ 
|
 |
 |
 |
 |
Date :
2011-08-21 17:19:27 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Parse error: syntax error, unexpected T_VAR in C:\AppServ\www\CC\detail_edit.php on line 366
บรรทัดนี้ครับ var itemSel=document.frmMain.ddlSelect;
เอ่อผมสงสัยว่าไม่ต้อง select เรียกตารางเหรอครับ ว่ามันจะคืนค่าจากตารางไหน
|
 |
 |
 |
 |
Date :
2011-08-21 17:46:16 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำเป็น Loop ใน JavaScript ครับ
|
 |
 |
 |
 |
Date :
2011-08-21 19:41:49 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมก็ทำในลูปจาวานะครับ - -*
|
 |
 |
 |
 |
Date :
2011-08-21 20:39:11 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ขึ้นครับ รันไม่ติด error แล้วครับ แต่ไม่ขึ้น
|
 |
 |
 |
 |
Date :
2011-08-21 20:57:29 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมให้ดูโค๊ดนะครับ ตอนเก็บ ผมเก็บเป็น array นะครับ
Code (PHP)
<script language="JavaScript">
function setDefault2()
<?
$strSQL = "SELECT * FROM tel WHERE id_detail = '".$_GET["detail_1"]."' ";
$objQuery = mssql_query($strSQL);
$objResult = mssql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found id_tel=".$_GET["tel_1"];
}
else
{
$strtel=$objResult["tel"];?>
{
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="1")
{
itemSel.options[x].selected = true;
break;
}
}
}
</script>
<body OnLoad="setDefault2();setDefault();" >
<form id="form1" name="frmMain">
<select id="ddlSelect" name="ddlSelect[]" multiple="multiple" size="6" >
<?
$number=$_POST['ddlSelect'];
if($number){
foreach ($number as $n){echo 'You selected ',$n,'<br />';}
}
?>
</select>
|
 |
 |
 |
 |
Date :
2011-08-21 23:25:44 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<script language="JavaScript">
function setDefault2()
var itemSel=document.frmMain.ddlSelect;
<?
$strSQL = "SELECT * FROM tel WHERE id_detail = '".$_GET["detail_1"]."' ";
$objQuery = mssql_query($strSQL);
$objResult = mssql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found id_tel=".$_GET["tel_1"];
}
else
{
$strtel=$objResult["tel"];?>
{
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="<?=$strtel;?>")
{
itemSel.options[x].selected = true;
break;
}
}
}
</script>
<body OnLoad="setDefault2();setDefault();" >
<form id="form1" name="frmMain">
<select id="ddlSelect" name="ddlSelect[]" multiple="multiple" size="6" >
<?
$number=$_POST['ddlSelect'];
if($number){
foreach ($number as $n){echo 'You selected ',$n,'<br />';}
}
?>
</select>
|
 |
 |
 |
 |
Date :
2011-08-21 23:27:11 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ขึ้นอะครับพี่วิน ใส่ var itemSel=document.frmMain.ddlSelect; ข้างบนก่อน function ใช่ไหมครับ
|
 |
 |
 |
 |
Date :
2011-08-21 23:33:58 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่ขึ้นอะครับพี่วิน
|
 |
 |
 |
 |
Date :
2011-08-22 08:22:37 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลอง echo ค่าต่างๆมาดูนะครับ ผลที่ได้คือ
เริ่มจาก $strSQL = "SELECT * FROM tel WHERE id_detail = '".$_GET["detail_1"]."' "; ผลที่ได้ = 86 ซึ่งถูกต้องครับเป็นเลขของธุรกิจ
$strtel=$objResult["tel"];?>
if (itemSel.options[x].value=="<?=$strtel?>")
ผลที่ได้จากการ echo $strtel คือ 1 ครับ ซึ่งถูกต้อง แต่ที่จริงมันต้องออก 1 2 3 4 5 6 7 ครับ
แต่ผม งง ว่าทำไมมันไม่คืนค่าใน listmenu
|
 |
 |
 |
 |
Date :
2011-08-22 11:17:14 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผลลองรันใน firefox แล้ว alt+shift+J แล้วดูผลของ javascript ผลก็ ok นะครับ แต่มันไม่ขึ้นอะครับ พี่วินอย่าเพิ่งทิ้งผมนะครับ - -* ช่วยผมนิดนึง
อันนี้ผลจาก java
Code (PHP)
<script language="JavaScript">
function setDefault2()
{
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="1")
{
itemSel.options[x].selected = true;
break;
}
}
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="2")
{
itemSel.options[x].selected = true;
break;
}
}
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="3")
{
itemSel.options[x].selected = true;
break;
}
}
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="4")
{
itemSel.options[x].selected = true;
break;
}
}
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="5")
{
itemSel.options[x].selected = true;
break;
}
}
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="6")
{
itemSel.options[x].selected = true;
break;
}
}
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="7")
{
itemSel.options[x].selected = true;
break;
}
}
}
</script>
|
 |
 |
 |
 |
Date :
2011-08-22 13:49:11 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดียวเย็น ๆ ซะ 2 ทุ่มกว่า ๆ ทักมาน่ะครับ เดียวจะดูให้ครับ
|
 |
 |
 |
 |
Date :
2011-08-22 14:15:05 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
2 ทุ่มแล้วครับ มาทวงสัญญา อิอิ
|
 |
 |
 |
 |
Date :
2011-08-22 19:56:58 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดียวไปกินข้าวก่อนครับ 
|
 |
 |
 |
 |
Date :
2011-08-22 21:04:39 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
- -zzZ
|
 |
 |
 |
 |
Date :
2011-08-22 22:38:47 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สงสัยไม่ทันแล้ว เพิ่งเสร็จธุระ ง่วงมากเลย เดียวพรุ่งนี้พี่จะมาทวงให้แต่เช้าครับ 
|
 |
 |
 |
 |
Date :
2011-08-22 22:39:51 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ครับ
|
 |
 |
 |
 |
Date :
2011-08-23 09:11:43 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่วินคร้าบบบ!!! ช่วยทีครับ
|
 |
 |
 |
 |
Date :
2011-08-23 13:12:48 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
...
|
 |
 |
 |
 |
Date :
2011-08-23 19:30:54 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มาแล้วครับ พอดียุ่งทั้งวันเลย ติดตรงไหนครับ
|
 |
 |
 |
 |
Date :
2011-08-23 20:49:50 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ค่าไม่เข้าไปใน listmenu แบบ multiple อะครับ แต่ว่าลองดูใน alt+shift+J ของ firefox ผลลัพท์ของจาวาสคริปมันก็ขึ้นครับ แต่ค่าไม่ถูกส่งไป
|
 |
 |
 |
 |
Date :
2011-08-23 21:15:51 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา Code ที่เราเขียนมาให้หน่อยครับ
|
 |
 |
 |
 |
Date :
2011-08-23 21:30:05 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<script language="JavaScript">
function setDefault2()
{
<?
$strSQL = "SELECT * FROM tel WHERE id_detail = '".$_GET["detail_1"]."' ";
$objQuery = mssql_query($strSQL);
while($objResult = mssql_fetch_array($objQuery))
{
if(!$objResult)
{
echo "Not found id_tel=".$_GET["tel_1"];
}
else
{
$strtel=$objResult["tel"];?>
var itemSel=document.frmMain.ddlSelect;
for (x=0;x<itemSel.length;x++)
{
if (itemSel.options[x].value=="<?=$strtel?>")
{
itemSel.options[x].selected = true;
break;
}
}
<? }} ?>
}
</script>
<body OnLoad="setDefault();setDefault2();" oncontextmenu="return false" onselectstart="return false" ondragstart="return false" >
<form id="form1" name="frmMain" method="post" onSubmit="JavaScript:return fncSubmit();" action="detail_update.php?detail_1=<?=$_GET["detail_1"];?>';">
<select id="ddlSelect" name="ddlSelect[]" multiple="multiple" size="6" >
<?
$number=$_POST['ddlSelect'];
if($number){
foreach ($number as $n){echo 'You selected ',$n,'<br />';}
}
?>
</select>
|
 |
 |
 |
 |
Date :
2011-08-23 21:32:31 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่วินครับ T_T
|
 |
 |
 |
 |
Date :
2011-08-24 10:35:12 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ไหมครับพี่วิน
|
 |
 |
 |
 |
Date :
2011-08-24 12:44:25 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา Database ลงมาด้วยครับ เดียวจะมาดูให้ครับ
บางทีอาจจะเข้ามาช้าน่ะครับ
|
 |
 |
 |
 |
Date :
2011-08-24 12:58:26 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2011-08-24 13:49:08 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมสงสัยมากทำไมไม่ออก
|
 |
 |
 |
 |
Date :
2011-08-24 20:22:46 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำได้แล้วครับ
Code (PHP)
<select id="ddlSelect" name="ddlSelect[]" multiple="multiple" size="6" >
<?
$strDDL = "SELECT * FROM tel WHERE id_detail = '".$_GET["detail_1"]."' ";
$queryDDL= mssql_query($strDDL);
while($rsDDL=mssql_fetch_array($queryDDL)){
echo "<option value='".$rsDDL['tel']."'>".$rsDDL['tel']."</option>";
}
$number=$_POST['ddlSelect'];
if($number){
foreach ($number as $n){echo 'You selected ',$n,'<br />';}
}
?>
</select>
|
 |
 |
 |
 |
Date :
2011-08-25 20:53:54 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|