|
 |
|
เกี่ยวกับ Checkbox เมื่อ Onclick ให้มันส่งค่าไปด้วย |
|
 |
|
|
 |
 |
|
คุณ mr.win ค่ะ
คือว่ามัน submit แต่เวลา checked แต่ว่า unchecked มันไม่ submit อ่ะค่ะ ()
เพราะว่าต้องการ ให้มันส่งค่า POST ไปด้วยเสมอ เพื่อไปอัพเดตที่ ค่า ที่ฐานข้อมูล
ถ้า checked Value=1
ถ้ามัน checked อยู่ แล้วเราไปคลิกให้มัน Unchecked ให้มันมี Value=0
แล้วไปบันทึกลงฐานข้อมูลค่ะ ตอนนี้ติดปัญหาที่เวลา กด Unchecked แล้วมันไม่ Submit
|
 |
 |
 |
 |
Date :
2010-12-15 10:04:48 |
By :
Avrill |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะมีใครช่วยได้บ้างน้าา
|
 |
 |
 |
 |
Date :
2010-12-15 12:53:58 |
By :
Avrill |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<input type="checkbox" name="chk" OnClick="Javascript: if(this.checked){this.value='1'}else{this.value='0'};alert(this.value);">
ใช่อย่างนี้ป่ะครับ
|
 |
 |
 |
 |
Date :
2010-12-15 13:05:30 |
By :
ไวยวิทย์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<input type="checkbox" name="chk" OnClick="Javascript: if(this.checked){this.value='1'}else{this.value='0'}; document.getElementById('form1').submit();">
document.getElementById('form1').submit(); คืออ้างอิงไอดีของ form ที่สับมิท
แล้วไม่ทราบว่า แล้วถ้าจะให้มัน Submit พร้อมกับส่งค่าไปด้วยยังไงค่ะ ของคุณเน๊่ยะ หมายถึง เมื่อเวลาไม่เช็ค ก็ submit ไปด้วยใช่หรือไหม่
แล้วหน้ารับค่าของคุณจะรับค่ายังไงล่ะครับ checkbox จะรับค่าอีกหน้าหนึ่งหลังจาก submit ได้ก็ต่อเมื่อ checked ไม่ใช่เหรอ
ทำไมไม่รับอีกหน้าหนึ่ง เป็น
<?php
if(empty($_POST['chk']){
$chk = '0';
}else{
$chk = $_POST['chk'];
}
?>
|
 |
 |
 |
 |
Date :
2010-12-15 13:41:06 |
By :
ไวยวิทย์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1.html
Code (JavaScript)
<input type="checkbox" name="chk" OnClick="update(this.value,);"><span id="action1"></span>
<script language="javascript" type="text/javascript">
function update(value){
$.ajax({
type: "GET",url: "update_data.php",data: "action=updateData&id=1&value="+value+"&dumy="+Math.random(),timeout: 6000,dataType: "text/html",
error: function(){alert('Loading time out');},
beforeSend: function(){$("#action1").html("<img src='images/loading.gif'>");},
success: function(html){$("#action1").html(html);}
});
}
</script>
update_data.php
<?
if($_GET["action"=="updateData"){
//$sql="update table set field=".(int)$_GET["value"]." where field=".(int)$_GET["id"];
//query sql
echo "";
}
?>
|
 |
 |
 |
 |
Date :
2010-12-15 14:07:08 |
By :
ชินอิจิคุง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?
$aRow=Array();
$chkDel=Array();
//echo $_POST["btnDelete"];
if($_POST["btnDelete"]=="OK"){
for($i=0;$i<count($_POST["aRow"]);$i++){
//echo $_POST["aRow"][$i]."<br>";
//echo $_POST["chkDel"][$i]."<br>";
if($_POST["chkDel"][$i]==""){
$approve=0;
} else {
$approve=$_POST["chkDel"][$i];
}
$strSQLu = "UPDATE dt_user SET user_type=".$approve." WHERE user_no='".$_POST["aRow"][$i]."'";
$objQueryu =mysqli_query($objCon,$strSQLu);
ECHO $strSQLu."<BR>";
}
}
?>
<!----------from----------!>
<form name="frmMain" action="<?=$_SERVER["SCRIPT_NAME"]?>" method="post" OnSubmit="return onDelete();">
<input type="text" name="aRow[]" value="<?=$objResult["user_no"];?>">
<input type="text" name="chkDel[]" id="active<?=$No?>" /><br>
<input name="checkbox<?=$No?>" ID="checkbox<?=$No?>" type="checkbox" onclick="calc<?=$No?>()">
<script type="text/javascript">
function calc<?=$No?>() {
var checkBox = document.getElementById("checkbox<?=$No?>");
var text = document.getElementById("active<?=$No?>");
if (checkBox.checked == true){
text.value = "51";
} else {
text.value = "";
}
}
</script>
<!----------from----------!>
<form name="frmMain" action="<?=$_SERVER["SCRIPT_NAME"]?>" method="post" OnSubmit="return onDelete();">
<input type="text" name="aRow[]" value="<?=$objResult["user_no"];?>">
<input type="text" name="chkDel[]" id="active<?=$No?>" /><br>
<input name="checkbox<?=$No?>" ID="checkbox<?=$No?>" type="checkbox" onclick="calc<?=$No?>()">
<script type="text/javascript">
function calc<?=$No?>() {
var checkBox = document.getElementById("checkbox<?=$No?>");
var text = document.getElementById("active<?=$No?>");
if (checkBox.checked == true){
text.value = "51";
} else {
text.value = "";
}
}
</script>
|
 |
 |
 |
 |
Date :
2023-11-27 12:27:26 |
By :
chaisofts thailand |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<form name="frm">
<input typp=hidden name=chk value=0 >
<input type=checkbox onclick="frm.chk.value=this.checked? 1:0" >
</form>
|
 |
 |
 |
 |
Date :
2023-11-28 14:40:45 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|