Skip to content

Instantly share code, notes, and snippets.

@vfontjr
Last active November 13, 2020 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfontjr/a37aec2c931c9d9a2a3e70fb21baba4f to your computer and use it in GitHub Desktop.
Save vfontjr/a37aec2c931c9d9a2a3e70fb21baba4f to your computer and use it in GitHub Desktop.
Source code for https://formidable=masterminds.com/change-input-background-color-based-on-other-field-value/
<style type="text/css">
.color_red {
background-color: red !important;
color: #fff !important;
}
.color_yellow {
background-color: yellow !important;
color: #000 !important;
}
.color_green {
background-color: green !important;
color: #fff !important;
}
</style>
<script>
jQuery(document).ready(function($){
"use strict";
/* replace llopn with the number field's key in the field's Advanced section */
$("#field_llopn").on("change", function () {
var num_value = $(this).val();
/* first remove any color classes that have already been applied
* change h6ub8 to the other field's key in the field's Advanced section
*/
$("#field_h6ub8").removeClass("color_red");
$("#field_h6ub8").removeClass("color_yellow");
$("#field_h6ub8").removeClass("color_green");
/* set the new color class */
switch (num_value) {
case "1" :
$("#field_h6ub8").addClass("color_red");
break;
case "2" :
$("#field_h6ub8").addClass("color_yellow");
break;
default :
$("#field_h6ub8").addClass("color_green");
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment