Issue
I'm trying to adopt this code taken from w3school.com but cannot see how I can preset the buttons by PHP based on the value stored in a Boolean MySQL column.
<form>
What color do you prefer?<br>
<input type="radio" name="colors" id="yes" value="1" >Yes<br>
<input type="radio" name="colors" id="no" value="0" >No
</form>
<button onclick="check()">Check "Yes"</button>
<button onclick="uncheck()">Uncheck "Yes"</button>
<script>
function check() {
document.getElementById("yes").checked = true;
}
function uncheck() {
document.getElementById("yes").checked = false;
}
</script>
Solution
You can use checked attribute with echo.
I don't know how you get your data but for exemple :
<form>
What color do you prefer?<br>
<input type="radio" name="colors" id="yes" value="1" >Yes<br>
<input type="radio" name="colors" id="no" value="0" <?php echo $variableOnMyDatabase ? "checked": "" ?> >No
</form>
Answered By - Rocket
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.