Reputation: 21
<input type="text" id="A1" name="A1">
In the box above, 0 or 1 is placed from mysql (fetch in box). Now I want that:
value box = 0 >> checkbox is unchecked
value box = 1 >> checkbox is checked
How to use a checkbox (type="checkbox") instead of text (type="text")?
<input type="checkbox" id="A1" name="A1">
Upvotes: 1
Views: 1744
Reputation: 962
Hello Reza Hatami,
Try this below code,
$my_checkbox
variable inside store data retrive from mysql data base.
<?php
$my_checkbox = 1;
?>
<input type="checkbox" id="Notification" name="Notification" <?php echo if($mycheckbox == 1) ? 'checked=""': ""; ?> />
also using, But in this some problem is some browser or php version not support so my advise use above code.
<?php
$my_checkbox = 1;
?>
<input type="checkbox" id="Notification" name="Notification" <?=($my_checkbox == 1) ? "checked" : "" ?> />
I hope my answer is helpfull. If any query so comment please.
Upvotes: 0
Reputation: 2800
<input type="checkbox" id="A1" name="A1" <?php if($value==1) echo 'checked="checked"'; ?> >
$value
is from database
Upvotes: 0
Reputation: 69
You can use js
document.getElementById("A1").checked = true;
Upvotes: 0
Reputation: 16436
You can check do it like this:
<?php
$box_val = 1; // rertive this value from database
?>
<input type="checkbox" id="A1" name="A1" <?=($box_val == 1) ? "checked" : "" ?>>
Upvotes: 3
Reputation: 6923
You can do this:
<input id="A1" name="A1" checked="0" type="checkbox">
<script>
$('#A1').prop("checked",$mySqlValue);
</script>
If $mySqlValue==1
the box will be checked and if $mySqlValue==0
it will not be checked.
Upvotes: 1