jquery : Call function on select box change event
by Emmanuel Garcia
HTML
<select id="host">
<option value="">Select value</option>
<option value="stack">stack</option>
<option value="exchange">exchange</option>
<option value="something">something</option>
</select>
<span class="checkvalue">BRONZE</span>
<span class="checkvalue">SILVER</span>
<span class="checkvalue">GOLD</span>
<br><br>
<label>Select</label>
<input type="radio" name="radio" id="hola" value="radio">
<br><br>
<label>Select</label>
<input type="radio" name="radio" id="quehay" value="radio">
JavaScript
$(document).ready(function(){
function stack()
{
$('span').each(function() {
var value = $(this).text();
if (value == "BRONZE") {
} else {
$(this).css('background-color', 'yellow'); }})
}
function exchange()
{
$('span').each(function() {
var value = $(this).text();
if (value == "SILVER" || value == "BRONZE") {
} else {
$(this).css('background-color', 'yellow'); }})
}
function something()
{
$('span').each(function() {
var value = $(this).text();
if (value == "BRONZE" || value == "SILVER" || value == "BRONZE") {
} else {
$(this).css('background-color', 'yellow'); }})
}
$('#host').on('change', function() {
if ( $('#host').val() == 'stack' ) stack();
else if ( $('#host').val() == 'exchange' ) exchange();
else if ( $('#host').val() == 'something' ) something();
});
});
$(function(){
$('input[id="hola"]').click(function(){
if ($(this).is(':checked'))
{
$('span').each(function() {
var value = $(this).text();
if (value == "SILVER" || value == "BRONZE") {
} else {
$(this).css('background-color', 'yellow'); }})
}
});
});
$(function(){
$('input[id="quehay"]').click(function(){
if ($(this).is(':checked'))
{
$('span').each(function() {
var value = $(this).text();
if (value == "BRONZE") {
} else {
$(this).css('background-color', 'yellow'); }})
}
});
});