function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ksmoksmo 

Button should change color based on when text is entered

Hi,

I have a button which is a div element. The css for this button is that it is grey in color.

<div class="UpdateButton"> UPDATE </div> 
When text is inputted in the text box the color of the button should change to red.
<div class="textpanel"> <input type="text" size="35" /><br/></div>

Similrly ther eis a checkbox on visualforce componenet which is referenced on the visualforce page. If that checkbox is checked the button should change to red.
Best Answer chosen by ksmo
Abhishek M.Abhishek M.
Hi ksmo,
You can use the following code,
<div class="UpdateButton"> UPDATE </div> 
When text is inputted in the text box the color of the button should change to red.
<div class="textpanel">
<input type="text" size="35" onchange="changeColor();"/><br/>
</div>
<script>
function changeColor(){
document.getElementByClass("UpdateButton").background-color = red;
}
</script>

- Hope this helps

All Answers

Abhishek M.Abhishek M.
Hi ksmo,
You can use the following code,
<div class="UpdateButton"> UPDATE </div> 
When text is inputted in the text box the color of the button should change to red.
<div class="textpanel">
<input type="text" size="35" onchange="changeColor();"/><br/>
</div>
<script>
function changeColor(){
document.getElementByClass("UpdateButton").background-color = red;
}
</script>

- Hope this helps
This was selected as the best answer
ksmoksmo
Hi Abhishek Light 6

This worked when I changed the 

<div id="UpdateButton"> UPDATE </div> 

function changeColor(){
document.getElementById("UpdateButton").background-color = red;
}


Thanks!