locked
change color based on yes no RRS feed

  • Question

  • User-807418713 posted

    hello

    This is my code if its yes then it should come with green color

    if no then red color

    var textBox1 = document.getElementById('ctl00_ContentPlaceHolder1_T3');
    	var textBox2 = document.getElementById('ctl00_ContentPlaceHolder1_TextBox14');
    	
    	
    	if (textBox1.value == textBox2.value)
    		      document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").value = 'Yes';
    	else
    		 document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").value = 'No';

    how to set 

    Monday, October 7, 2019 6:25 PM

Answers

  • User61956409 posted

    Hi Gopi.MCA,

    this not working

      document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").style.color = "green";

    Does it cause error in browser console tab? Please use browser developer tool to check if the html of 'ctl00_ContentPlaceHolder1_TextBox24' control look like this:

    <input name="ctl00_ContentPlaceHolder1_TextBox24" id="ctl00_ContentPlaceHolder1_TextBox24" style="color: green;" type="text">

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 8, 2019 6:00 AM

All replies

  • User-474980206 posted

    You set color of an element with style or css, but what element did you want to set the color of, and what property (font color, border color, background color, etc)

    Tuesday, October 8, 2019 12:36 AM
  • User61956409 posted

    Hi Gopi.MCA,

    if its yes then it should come with green color

    if no then red color

    If you'd like to specify red/green color for the TextBox, you can refer to the following code snippet. 

    if (textBox1.value == textBox2.value) {
        document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").value = 'Yes';
        document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").style.color = "green";
    }
    else {
        document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").value = 'No';
        document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").style.color = "red";
    }

    Besides, if you want to apply custom styles to other elements, please clarify more about your requirement.

    With Regards,

    Fei Han

    Tuesday, October 8, 2019 1:59 AM
  • User-807418713 posted

    hi

    tried this not working

      document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").style.color = "green";
    Tuesday, October 8, 2019 5:45 AM
  • User61956409 posted

    Hi Gopi.MCA,

    this not working

      document.getElementById("ctl00_ContentPlaceHolder1_TextBox24").style.color = "green";

    Does it cause error in browser console tab? Please use browser developer tool to check if the html of 'ctl00_ContentPlaceHolder1_TextBox24' control look like this:

    <input name="ctl00_ContentPlaceHolder1_TextBox24" id="ctl00_ContentPlaceHolder1_TextBox24" style="color: green;" type="text">

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 8, 2019 6:00 AM
  • User-857013053 posted

    <style>

    .no_checked {
    background: #F5A9A9;
    }

    </style>

    <table id="qc_main_form">
    <tr class="color_hover">

    <td align="center">

    <input type="radio" name="group1" value="1" checked="checked" class="spacer" />Yes
    <input type="radio" name="group1" value="2" class="spacer" />No

    </td>

    </tr>

    </table>

    <script>

    $('input:radio[value=1]').click(function () {
    var $this = $(this);
    $this.closest('td').removeClass('no_checked');
    });
    $('input:radio[value=2]').click(function () {
    var $this = $(this);
    $this.closest('td').addClass('no_checked');
    });

    </script>

    Wednesday, October 9, 2019 4:33 AM