Lấy giá trị của thẻ Select Multiple bằng Javascript
RUN
<!DOCTYPE html> <html> <head> <title>Select Multiple</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <h2>Ví dụ được biên soạn tại freetuts.net</h2> <h3>Chọn các chuyên mục từ danh sách dưới đây</h3> <select multiple onchange="validateSelectBox(this)"> <option value="tin công nghệ">Tin công nghệ</option> <option value="tin thời sự">Tin thời sự</option> <option value="tin quốc tế">Tin quốc tế</option> <option value="tin thể thao">Tin thể thao</option> <option value="tin nông nghiệp">Tin nông nghiệp</option> </select> <h3>Danh sách chuyên mục bạn đã chọn:</h3> <div id="result"> Bạn chưa chọn chuyên mục nào </div> <script language="javascript"> function validateSelectBox(obj){ var options = obj.children; var html = ''; for (var i = 0; i < options.length; i++){ if (options[i].selected){ html += '<li>'+options[i].value+'</li>'; } } document.getElementById('result').innerHTML = html; } </script> </body> </html>
PHÓNG TO