I want to print a button value
come from PHP fetch but every time the value came with space before the text value for example " ON"
and I want it "ON"
My code in php file:
<?php
$DATABASE_HOST = 'ssite.com';
$DATABASE_USER = 'user';
$DATABASE_PASS = 'pass';
$DATABASE_NAME = 'db';
// Try and connect using the info above.
$db = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS,
$DATABASE_NAME);
if (!$db){
die("Connection Failed: ". mysqli_connect_error());
}
$db_select = "SELECT * FROM led WHERE id = 1";
$result = mysqli_query($db, $db_select);
if($result->num_rows == 1){
while($row = mysqli_fetch_assoc($result)){
echo($row['status']);
}
}
?>
In HTML for button:
<input type="button" id="ledonof" onclick="myFunction()" value="<?php
include ('led.php'); ?>">
my issue is here with the value output is come like this : " ON"
I don't know why the space is coming before the value?
Javascript file:
function myFunction(){
var ledactual=document.getElementById("ledonof").value
var ledon="ON"
var ledoff="OFF"
if (ledactual == ledoff){
$.get("led.php", function(led) {
$("#ledonof").prop('value',led);
})}
if (ledactual == ledon){
$.get("ledoff.php", function(ledoff) {
$("#ledonof").prop('value',ledoff);
})}
};