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 :
<?php
if($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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My New PHP CODE</title>
<link rel="stylesheet" href="bootStrap/css/bootstrap.css"/>
<link rel="stylesheet" href="bootStrap/css/bootstrap.min.css"/>
<script type="text/javascript">
function myFunction() {
document.getElementById("myID").style.color = "#ff0000";
}
</script>
</head>
<body>
<div class="container jumbotron text-center">
<form action="" method="POST" class="form-inline">
<div class="form-group">
<label for="fname" id="myID">FIRST NAME</label>
<input type="text" name="fname" class="form-control" >
<label for="nlame">LAST NAME</label>
<input type="text" name="lname" class="form-control" >
</div>
<br><br>
<div class="btn-group">
<button type="submit" name="save_button" onclick="myFunction();" <?php echo $isSaveDisabled? 'disabled':'';?>>SAVE</button>
<button type="submit" name="create_button" <?php echo $isCreateDisabled? 'disabled':''?> >CREATE</button>
</div>
</form>
</div>
<?php
if($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"