[英]How can I load a checkbox checked status from a mysql bool, and change the mysql bool in the database dynamically when the checkbox is checked?
[英]How can i update a value in mysql database with php when a checkbox is checked?
在數據庫中,我正在更新圖像的高度,在選中復選框后,我想查看具有該高度的圖像。知道我應該使用什么來實現這一點嗎? 一個例子將不勝感激。
好的,您需要做的是實現 ajax 以異步調用數據庫以更新數據庫中圖像的高度,並實現香草 JavaScript(或 jQuery)以在請求成功后調整圖像大小。
例如:
HTML
<input type="checkbox" name="your_checkbox" value="50" onclick="changeHeight(this);">
<img src="image/url/here.jpg" alt="foo" class="your-class" id="img">
JavaScript
let changeHeight = checkbox => {
if(checkbox.checked){
$.ajax({
url: 'your/path/to/updating/file.php',
type: 'POST',
data: {img_height: checkbox.value}
success: res => {
$('#img').css({height: checkbox.value+'px'});
},
error: err => {
console.error(err);
}
});
}
}
PHP
$height = $_POST['img_height'];
// query to update height in the database...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.