Asked by:
Validate label in HTML

Question
-
User1692641958 posted
Validate label in HTML
Hi, I need help, I want to validate in a label that when a condition is met it is hidden, if they could help.
an example when txtDescandoMedicoPreview = "NO", I want it to hide
Thank you<div class="col-md-3">
<label id="txtDescandoMedicoPreview">Descanso Medico:</label>
<label id="txtTrabajoRestringidoPreview">Trabajo Restringido:</label>
</div>Thursday, August 23, 2018 4:29 PM
All replies
-
User283571144 posted
Hi RockChris,
According to your description, I suggest you could try to use jquery to check if the label’s text.
If meets, you could use hide() to hide it.
For more details, you could refer to the code below.
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <form class="form-horizontal testForm"> <div class="col-md-3"> <label id="txtDescandoMedicoPreview">NO</label> <label id="txtTrabajoRestringidoPreview">Trabajo Restringido:</label> </div> </form> <script> $(document).ready(function () { if (document.getElementById("txtDescandoMedicoPreview").innerHTML == "NO") { $("#txtDescandoMedicoPreview").hide(); } }); </script> </body> </html>
Result:
Best Regards,
Brando
Friday, August 24, 2018 8:37 AM -
User1692641958 posted
I already tried but I get error
this is my sript:
var descansoMedico = "Descanso Medico: NO";
var trabajoRestringido = "Trabajo Restringido: NO";
var trabajoRestringidoFechaInicio = "Fecha Inicio:";
var trabajoRestringidofechaFin = "Fecha Fin:";if ($('#rbtDescansoMedicoIP').is(':checked')) {
descansoMedico = "Descanso Medico: SI";
trabajoRestringidoFechaInicio = "Fecha Inicio: " + $("#txtFechaInicioDMIP").val();
trabajoRestringidofechaFin = "Fecha Fin: " + $("#txtFechaFinDMIP").val();
}
if ($('#rbtTrabajoRestringidoIP').is(':checked')) {
trabajoRestringido = "Trabajo Restringido: SI";
}$("#txtDescandoMedicoPreview").text(descansoMedico);
$("#txtTrabajoRestringidoPreview").text(trabajoRestringido);Friday, August 24, 2018 6:02 PM -
User283571144 posted
Hi RockChris,
According to your codes, I still couldn't understand clearly about your requirement.
Do you mean you want to check descansoMedico value?
If this value contains No, it will hide the txtDescandoMedicoPreview label?
If this is your requirment, I suggest you could try below codes:
var descansoMedico = "Descanso Medico: NO"; var trabajoRestringido = "Trabajo Restringido: NO"; var trabajoRestringidoFechaInicio = "Fecha Inicio:"; var trabajoRestringidofechaFin = "Fecha Fin:"; if ($('#rbtDescansoMedicoIP').is(':checked')) { descansoMedico = "Descanso Medico: SI"; trabajoRestringidoFechaInicio = "Fecha Inicio: " + $("#txtFechaInicioDMIP").val(); trabajoRestringidofechaFin = "Fecha Fin: " + $("#txtFechaFinDMIP").val(); } if ($('#rbtTrabajoRestringidoIP').is(':checked')) { trabajoRestringido = "Trabajo Restringido: SI"; } if(descansoMedico == "Descanso Medico: NO"){ $("#txtDescandoMedicoPreview").hide(); }else { $("#txtDescandoMedicoPreview").text(descansoMedico); } $("#txtTrabajoRestringidoPreview").text(trabajoRestringido);
If this doesn't match your requirement, please post the details html codes and description of your requirement.
Best Regards,
Brando
Tuesday, August 28, 2018 9:15 AM -
User1204533129 posted
don't forgot to drag jquery library file min.js to your page .
try this
$('#txtTrabajoRestringidoPreview').hide();
Best regards,
kamal.
Thursday, October 4, 2018 7:11 PM