I want to check if the value true is present in a db and if present i want to hide a partcular id using javascript.
I know both parts - how to check database and hide elements with js.
the question is - how do i integrate both parts?
Ex - Check if in table "Tutorials", the value "true" is present or not. If yes, document.getelementbyid(box).style.display :none;
How do i integrate both? thanks.
Nest your php within your javascript call. The PHP will get processed at the server side, and will return a boolean, then use that to be part of an if block to decide what to hide
if (<?php Check database and return boolean ?>){
$('#box').hide();
}
You can do so through AJAX. From your page, you send a request to server-side language whose return value can be used in your condition.
For example, here is sample code with jQuery:
$.ajax({
type:'POST',
url:'your_file.php'
success:function(response){
if (response == 'true'){
$('#box').hide();
}
}
});
And from your server-side script, you get the value of required field from database and if it exists, you output 'true'
from it.
If you don't want to use jQuery and go with vanilla javascript, you can check out this tutorial for ajax: