peri hoki perihoki clarustologistics rimashaop.com angelpaintingtools.co.in vrjanaenergies.com cara scatter hitam maxwin spesifikasi scatter emas mahjong rtp mahjong wins 3 medan pola malam pgsoft cairkan 813jt keberuntungan tukang parkir cek rtp mahjong ways lebaran kisah inspiratif kuli bangunan menang mahjong wins peluang profit rtp mahjong ways 2 naik sopir angkot jackpot 89 juta mahjong wins temuan scatter jumat mahjong ways keajaiban malam menghidupkan suasana menang dengan gaya strategi cerdas mahjong putaran ajaib mahjong wins tumbang bahagia raup untung dengan trik scatter mahjong scatter hitam mahjong ways mengantarkan kemenangan tak terduga fenomena scatter hitam saat jam sepi server kemenangan besar dari scatter hitam mahjong ways pekerja serabutan raih jackpot mengagumkan di mahjong ways potensi emas setiap spin mahjong ways waktu spin terbaik untuk scatter hitam tukang becak raih rejeki di mahjong
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 282
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent
Filename: Session/Session.php
Line Number: 294
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 304
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 314
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 315
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 316
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 317
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 375
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: drivers/Session_files_driver.php
Line Number: 108
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_save_handler(): Cannot change save handler when headers already sent
Filename: Session/Session.php
Line Number: 110
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Cannot start session when headers already sent
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
Lấy giá trị checkbox checked bằng Javascript
CĂN BẢN
DOM & BOM
XỨ LÝ FORM
JAVASCRIPT TIPS
TUTORIALS
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
Lấy giá trị checkbox checked bằng Javascript
Giả sử có chương trình lấy thông tin về sở thích của người dùng, mỗi sở thích là một checkbox và nếu người dùng thích cái nào thì check vào cái đó. Hãy tạo ra một button xử lý khi click vào button đó thì hiển thị danh sách các sở thích mà người dùng đa chọn.
Bài viết này được đăng tại freetuts.net , không được copy dưới mọi hình thức.
Để lấy giá trị của checkbox thì ta sử dụng cú pháp như sau.
Trong đó checkboxObj
là một đối tượng HTML được lấy bởi DOM (tham khảo một số cách truy vấn DOM thông dụng ).
Bài viết này được đăng tại [free tuts .net]
Nếu checkboxObj
là một mảng các đối tượng checkbox thì bạn phải sử dụng vòng lặp để lặp qua từng phần tử và lấy giá trị. Như trong đề bài này là ta thấy có nhiều checkbox nên chắc chắn là phải sử dụng cách này.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Javascript Example</title>
</head>
<body>
<h2>Lấy giá trị của checkbox bằng Javascript</h2>
<p>Hãy viết chương trình khi click vào button thì in ra danh sách sở thích mà người dùng đã chọn.</p>
<input type="checkbox" name="hobby" value="Đi chơi"/> <label>Đi chơi</label> <br/>
<input type="checkbox" name="hobby" value="Đi du lịch"/> <label>Đi du lịch</label> <br/>
<input type="checkbox" name="hobby" value="Đi ăn"/> <label>Đi ăn</label> <br/>
<input type="checkbox" name="hobby" value="Đi siêu thị"/> <label>Đi siêu thị</label> <br/>
<input type="checkbox" name="hobby" value="học lập trình"/> <label>học lập trình</label> <br/>
<input type="checkbox" name="hobby" value="Lướt freetuts.net"/> <label>Lướt freetuts.net</label>
<br/> <br/>
<input type="button" id="btn" value="Xem kết quả"/>
<script language="javascript">
document.getElementById('btn').onclick = function()
{
// Khai báo tham số
var checkbox = document.getElementsByName('hobby');
var result = "";
// Lặp qua từng checkbox để lấy giá trị
for (var i = 0; i < checkbox.length; i++){
if (checkbox[i].checked === true){
result += ' [' + checkbox[i].value + ']';
}
}
// In ra kết quả
alert("Sở thích là: " + result);
};
</script>
</body>
</html>
Cùng chuyên mục: