Changing the background color of a textbox

mlapl1
mlapl1 Community Member Posts: 350 ☆ Roadie ☆
Hello again (after a very long time).

I have the following JS for changing the background of a textbox. It works fine when I place it in an OnMclk action.

function checkFilled() {
var inputVal = document.getElementById("text31706");
inputVal.style.backgroundColor = "yellow";
}
checkFilled();

However, I want to implement this in many buttons and using many different text boxes. I therefore need to be able to read the html name of each textbox into the JS. How can I achieve that? One thought was to have an OnMclk action that reads the html name into a Lectora variable which is then read into the JS script in the usual way. But... how do I do that??? Or is there a better solution?

Thanks so much for your help.
Andrew

Comments

  • susanmacnab
    susanmacnab Community Member, Lectora® Accessibility Group (LAUG) Member, eLearning Brothers® Partner Posts: 16 ♪ Opening Act ♪
    Hi Andrew,

    Do you want to change a bunch of text fields all at once? If so, you could assign them all the same class name by clicking on the Appearance window in the Text Properties ribbon.





    In my example above, I used the class name highlight.

    Then on your button click action, run the following jquery/javascript command (change the class name to whatever you set above):

    triv$('.highlight').css("background-color", "yellow");

    You can assign multiple class names to each text field so you can highlight different combinations of fields from different buttons if desired.

    Hope this helps!