Necesito ayuda. Nuevo en JS y HTML. Estoy tratando de obtener una casilla de verificación para cambiar cualquier resultado de nulo a A.
A, nulo, A, A o cualquier otra combinación debe ser el resultado
El resultado sigue mostrando solo nulo, nulo, nulo, nulo y en html en lugar del cuadro de resultados
https://jsfiddle.net/uw21myj8/
var k1 = 'null'; var k2 = 'null'; var k3 = 'null'; var k4 = 'null'; $(function(){ $('#checkbox').change(function() { $("#text").val($(this).is(':checked') ? "A" : "B"); k1 = 'C5'; }); }); $(function(){ $('#checkbox1').change(function() { $("#text1").val($(this).is(':checked') ? "A" : "B"); k2 = 'C5'; }); }); $(function(){ $('#checkbox2').change(function() { $("#text2").val($(this).is(':checked') ? "A" : "B"); k3 = 'C5'; }); }); $(function(){ $('#checkbox3').change(function() { $("#text3").val($(this).is(':checked') ? "A" : "B"); k4 = 'C5'; }); }); var results = (k1 + ', ' + k2 + ', ' + k3 + ', ' + k4 + ', '); function getresults(){ $("#result").text(results); console.log(results); };Tu JS necesita algunos ajustes:
var k1 = 'null'; var k2 = 'null'; var k3 = 'null'; var k4 = 'null'; $(function(){ $('#checkbox').change(function() { $("#text").val($(this).is(':checked') ? "A" : "B"); k1 = $(this).is(':checked') ? "A" : "null"; }); }); $(function(){ $('#checkbox1').change(function() { $("#text1").val($(this).is(':checked') ? "A" : "B"); k2 = $(this).is(':checked') ? "A" : "null"; }); }); $(function(){ $('#checkbox2').change(function() { $("#text2").val($(this).is(':checked') ? "A" : "B"); k3 = $(this).is(':checked') ? "A" : "null"; }); }); $(function(){ $('#checkbox3').change(function() { $("#text3").val($(this).is(':checked') ? "A" : "B"); k4 = $(this).is(':checked') ? "A" : "null"; }); }); function getresults() { var results = (k1 + ', ' + k2 + ', ' + k3 + ', ' + k4 + ', '); $("#result").text(results); console.log(results); };