09/10/2018, 17:42
Nhờ các bạn giúp đỡ gấp !
Bạn nào có cái java script để lấy các giá trị được chọn trong combo list (<select name="abc" multiple>.... </select>) thì cho mình xin với. Cảm ơn các bạn thật nhiều.
Bài liên quan





Thí dụ đây :
<FORM>
<SELECT NAME="liste" SIZE="1">
<OPTION SELECTED VALUE="">Choisissez</OPTION>
<OPTION VALUE="index.htm">Index</OPTION>
<OPTION VALUE="suscribe.htm">Inscription</OPTION>
<OPTION VALUE="aparaitr.htm">A paraître</OPTION>
</SELECT>
<INPUT TYPE="button" VALUE="Allez" onClick="if (form.liste.selectedIndex != 0) window.open(form.liste.options[form.liste.selectedIndex].value, 'Abonnement', 'scrollbars=yes,status=yes,width=500,height=300'); else alert('Veuillez faire un choix')">
</FORM>
Chúc thành công.
form.liste.options[form.liste.selectedIndex].value[i]
Vui lòng giúp em vấn đề này với nhé.
Cảm ơn anh thật nhiều.
<html> <head> <title>Test Multiple Selected List</title> <script language="JavaScript"> function ShowSelectedItems() { theList = document.myform.liste; for (i=0; i < theList.options.length; i++) { if (theList.options[i].selected) { alert(theList.options[i].value); } } } </script> </head> <body> <form id="myform" name="myform" action="#"> <select id="liste" name="liste" multiple> <option value="Hehe">Hehe</option> <option value="Huhu">Huhu</option> <option value="Haha">Haha</option> </select> <br> <input type="button" onclick="ShowSelectedItems();" value="Show"> </form> </body> </html>Ví dụ script này lưu giá trị được chọn trong strValues.
function saveMe() { var strValues = ""; var boxLength = document.frmGroup.lstGroupUser.length; var count = 0; if (boxLength != 0) { for (i = 0; i < boxLength; i++) { if (count == 0) { strValues = document.frmGroup.lstGroupUser.options[i].value; } else { strValues = strValues + "," + document.frmGroup.lstGroupUser.options[i].value; } count++; } } if (strValues.length == 0) { alert("You have not made any selections"); } else { alert("Here are the values you've selected:\r\n" + strValues); } }phía trên dòng alert("Here are the values you've selected:\r\n" + strValues); | bạn nhập thêm một đoạn mã nhỏ nữa
document.frmGroup.mydata.value = strValues;
khi xử lý dữ liệu ở phía server ( mình chỉ bít php thui ) thì bạn đơn giản là request biến mydata từ $_POST hoặc $_GET , sau đó xài hàm explode() để "phá" chuỗi này ra thành 1 mảng và xử lý bình thường .