Using CSS to format a file in a form gives me trouble

I have a table, and each row contains a color name and the hex value I chose for that color

In a form I want to change the background of a field based on the HEX value.

This is the code I use in an AJAX onChange of the color code.

$clr=  {colorHtml};


			#id_sc_field_swatch {
			  background-color: <?php echo $clr ?>;} 

when I run it, and change the color, it changes the background of the field as I expect (see attached), but it also gives me a yellow output box which I interpret as an error in the CSS.

After I close the yellow box, the colouring disappears, as follows

I can turn off the AJAX error notification which suppresses the box, but then I never see any colouring of the field at all.

Has anyone experienced this?

I have learned a little more.

This code works fine if placed in an onLoad event, but not in an AJAX event.

I think this is a bug, yet I need a work around. How do I invoke the code when I change the value of a field.

If you put the code in a php program and call the program from the ajax event does it work?

Try to make a javascript function that has two parameters, ad id and the color, then this function set the backgroud color.

In the ajax evet, just use the sc_ajax_javascript macro giving the function name, the id and the color.