Skip to content Skip to sidebar Skip to footer

How To Change Label Color In Javascript On Submit Button

Hello Friend i have problem in my code, In this code i want when i press save button then 'Hello PHP' print and label color of FIRST NAME change but it's not work, when I put submi

Solution 1:

Label changes color after ckick on submit but page is refreshing immediately. You can color the label by checking if button "save" was clicked :

<?phpif($isSaveDisabled) {
  echo'<script>document.getElementById("myID").style.color = "#ff0000";</script>'
}
?>

Therefore your code will look:

<?php//php code $isSaveDisabled=true;
$isCreateDisabled=false;

if(isset($_POST['save_button']))
{
echo'Hello PHP';
}

if(isset($_POST['create_button']))
{
$isSaveDisabled=false;
}
?>
// BootStrap Code
<!DOCTYPE html><html><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><title>My New PHP CODE</title><linkrel="stylesheet"href="bootStrap/css/bootstrap.css"/><linkrel="stylesheet"href="bootStrap/css/bootstrap.min.css"/><scripttype="text/javascript">functionmyFunction() {
document.getElementById("myID").style.color = "#ff0000";
}
</script></head><body><divclass="container jumbotron text-center"><formaction=""method="POST"class="form-inline"><divclass="form-group"><labelfor="fname"id="myID">FIRST NAME</label><inputtype="text"name="fname"class="form-control" ><labelfor="nlame">LAST NAME</label><inputtype="text"name="lname"class="form-control" ></div><br><br><divclass="btn-group"><buttontype="submit"name="save_button"onclick="myFunction();"<?phpecho$isSaveDisabled? 'disabled':'';?>>SAVE</button><buttontype="submit"name="create_button"<?phpecho$isCreateDisabled? 'disabled':''?> >CREATE</button></div></form></div><?phpif($isSaveDisabled) {
    echo'<script>document.getElementById("myID").style.color = "#ff0000";</script>';
  }
?></body></html>

Post a Comment for "How To Change Label Color In Javascript On Submit Button"