手始めにHTMLにチェックボックスを配置してリンクを飛ばす
<input type='checkbox' class='chk'>
<input type='checkbox' class='chk'>
$(function() {
$('.chk').change(function() {
location.href = "http://qiita.com";
});
});
内容的には,chkクラスがクリックされたらQiitaに飛ぶというものです
例のように複数あっても問題無いです.
PHPで動的に作って属性からリンクを取ってリンクを飛ばす
フォーム側
<?php
for ($i = 0 ; $i < 3 ; $i++) {
echo "<input type='checkbox' class='chk' data-id='" . $i . "'>";
}
?>
表示されるもの
HTMLソース
<input type='checkbox' class='chk' data-id='0'>
<input type='checkbox' class='chk' data-id='1'>
<input type='checkbox' class='chk' data-id='2'>
data-id
になっているものがデータベースに格納されているIDを想定
$(function() {
$('.chk').change(function() {
link = $(this).attr('data-id');
location.href = "search.php?id=" + link;
)};
)};
チェックボックスが押されたら検知をして,$(this)
に押されたチェックボックスをものとして持っているのでdata-id
の要素を引っ張ってくる
受け取り側
<?php
$id = $_GET['id'];
?>
URLのパラメータ名はGETメソッドなのでできる技ですね