動的に生成されるチェック ボックスがあります。チェック ボックスをオンにすると、onchange メソッドが正常に動作し、ユーザーがボックスをオフにすると、関数が呼び出されます。onchange メソッドが目的の関数を呼び出します。問題は、ボックスが一部にチェックされている場合です。ページのアクティブになるのは良いことですが、ユーザーがチェックボックスのチェックを外すと、ページのその部分が再びアクティブになり、チェックボックスの値は最初にチェックされた後も「チェック済み」のままです。ページのアクティブな部分が非アクティブになるように、ユーザーがチェックを外すことを選択したことを検出する方法はありますか。
フォームで送信せずに、チェック ボックスのステータスを送信できますか。投稿するには提出する必要がありますか。これには Java スクリプトを使用する必要がありますか?
これを試してみましたが、問題があります
<script type="text/jscript">
//this funciton will be called when user checks a check box.
function edit(){
//get selected category from the form
//var formName = 'choose';
//var Category = document[formName]['choose'].value;
//check if browser suports ajax
var xmlhttp = null;
if(typeof XMLHttpRequest != 'udefined'){
xmlhttp = new XMLHttpRequest();
}
else if(typeof ActiveXObject != 'undefined'){
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
else
throw new Error('You browser doesn\'t support ajax');
//open connection with activateImages.php to recieve the active images as an acho
xmlhttp.open("GET", "activateImages.php",true);
//echeck if ready to recieve
xmlhttp.onreadystatechange = function (){
if(xmlhttp.readyState == 4)
window.activate(xmlhttp);
};
xmlhttp.send(null);
}
//recieve the active images then insert them in the specified location of the page.
function activate(xhr){
if(xhr.status == 200){
document.getElementById('images').innerHTML = xhr.responseText;
}
else
throw new Error('Server has encountered an error\n'+
'Error code = '+xhr.status);
}
</script>