Reputation: 27
I am trying to change value on click and color too. I am able to change value via js but unable to change color. This is my Js code
<script type="text/javascript">
function change(el) {
if (el.value === "P")
el.value = "A";
else
el.value = "P";
}
</script>
And this is button:
<td>
<input id="press5" name="press5" type="button" value="<?php echo $ro5[$_SESSION['dyy']] ?>"
onclick="return change(this);" onBlur="checkAvailability5()" class="btn btn-primary"/>
</td>
Please help me out. thanks.
Upvotes: 0
Views: 59
Reputation: 413
This code will change your background color, font color & values of your input button. Working example here.
<input type="button" value="P" onclick="return change(this);"/>
<script type="text/javascript">
function change( el )
{
if ( el.value === "P" ){
el.value = "B";
el.style.backgroundColor = "lightblue";
el.style.color = "blue";
}else{
el.value = "P";
el.style.backgroundColor = "lightpink";
el.style.color = "red";
}
}
</script>
Upvotes: 1