พบกับบทความเกี่ยวกับคอมพิวเตอร์และ programming ได้ที่ http://articles.modoeye.com | บล็อกอาหาร
Javascript development / Menu Swapper
Mickey
Mickey
Tue 7 Mar 2006 15:09:02

ที่เป็น menu swapper เป็นการเลือกจาก select ตัวนึง ไปเก็บไว้ที่ select อีกตัวนึง แล้วต้องการที่จะนำข้อมูลจากตัวที่ 2 ไปบันทึกลงฐานข้อมูล โดยการกด submit ก่อน
อยากทราบว่าการบันทึกลงฐานข้อมูลจากที่ได้เลือกไว้ ซึ่งมีได้หลายค่า มีการส่งค่าที่จะไปบันทึกอย่างไรค่ะ รบกวนขอดูตัวอย่างประกอบด้วยน่ะค่ะ

Administrator
Tue 7 Mar 2006 17:03:27
การส่งค่าไปยังไฟล์อื่นๆก็เหมือนกับการส่งค่าทั่วไปครับ ซึ่งถ้าเป็น select object นั้นก็จะเป็นการส่งค่าที่ถูกเลือกอยู่นั้นไปในชื่อของ object นั้นๆทั้ง 2 ตัวครับ ซึ่งอยู่ที่ว่าคุณทำการส่งค่าไปแบบใดก็ทำการเขียนรับค่าแบบนั้นครับ
Mickey
Mickey
Tue 7 Mar 2006 18:12:43

ขอบคุณค่ะสำหรับคำแนะนำ
ที่ต้องการก็คือ ต้องเลือกข้อมูลในส่วนที่ 2 เอง ซึ่งมันไม่เลือกให้อัติโนมัติ แต่จิงๆ ต้องการให้เลือกในส่วนที่ 2 ทั้งหมด โดยที่ไม่ต้องเลือกเองอีกน่ะค่ะ และค่าที่ส่งก็จะเป็น array ด้วย  

Administrator
Tue 7 Mar 2006 19:17:10
การบันทึกคุณอาจจะใช้ Filed ที่เป็น text หรือ varchar ก็ได้ครับ โดยทำการคั่นแต่ละค่าด้วยตัวแบ่งด้วยอักขระแปลกๆเช่น |X|, {}, ซึ่งต้องไม่ผิด Syntax ของฐานข้อมูลนั้นๆด้วยครับ

ส่วนการนำมาแสดงผลนั้น ลองดูตัวอย่างนี้ครับ

<script language="JavaScript">
function move(fbox, tbox) {
    var arrFbox = new Array();
    var arrTbox = new Array();
    var arrLookup = new Array();
    var i;
    for (i = 0; i < tbox.options.length; i++) {
        arrLookup[tbox.options[i].text] = tbox.options[i].value;
        arrTbox[i] = tbox.options[i].text;
    }
    var fLength = 0;
    var tLength = arrTbox.length;
    for(i = 0; i < fbox.options.length; i++) {
        arrLookup[fbox.options[i].text] = fbox.options[i].value;
        if (fbox.options[i].selected && fbox.options[i].value != "") {
            arrTbox[tLength] = fbox.options[i].text;
            tLength++;
        }else{
            arrFbox[fLength] = fbox.options[i].text;
            fLength++;
          }
    }
    arrFbox.sort();
    arrTbox.sort();
    fbox.length = 0;
    tbox.length = 0;
    var c;
    for(c = 0; c < arrFbox.length; c++) {
        var no = new Option();
        no.value = arrLookup[arrFbox[c]];
        no.text = arrFbox[c];
        fbox[c] = no;
    }
    for(c = 0; c < arrTbox.length; c++) {
        var no = new Option();
        no.value = arrLookup[arrTbox[c]];
        no.text = arrTbox[c];
        tbox[c] = no;
   }
}
</script>

<form name="combo_box">
<table><tr><td>
<select id="list1" multiple size="10" name="list1" style="width:150">
<?
$db_value = array(1, 5, 9);

for($i = 0; $i < 10; $i++){
    echo "<option value=\"".$i."\"".((in_array($i, $db_value))?" selected":"").">".$i."</option>";
}
?>
</select>
</td>
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.list2,this.form.list1)" value="<<">
<input type="button" onClick="move(this.form.list1,this.form.list2)" value=">>">
</td>
<td>
<select id="list2" multiple size="10" name="list2" style="width:150">
</select>
</td></tr></table>
</form>
<script language="javascript">
function getObj(id){
    return document.all?document.all[id]:document.getElementById(id);
}
move(getObj("list1"),getObj("list2"));
</script>
Reply
Name:
E-mail:
Home | Services | Forum | Classified | Directories | Support | Contact
ATOM feed RSS 0.9 feed RSS 1.0 feed RSS 2.0 feed
Copyright © 2005 - 2007 Modoeye.com, All Rights Reserved.
Disclaimer | Privacy policy | Term of Use | Term of Services
Valid XHTML Valid CSS! PHP: Hypertext Preprocessor MySQL database Apache Powered! FreeBSD Power to serve
Modoeye Sitemap Client login