How to check two fields at the same time?

1

The following code is not returning false . When the reg2 field is empty and the reg1 field is selected, the function should return false , but this is not happening.

Here is the code for review: Script that releases the div with input.

$j("#reg_2").hide();
	$j("#reg1").click(function() {
	if($j("#reg1").is(':checked')){
	$j("#reg_2").show();
	} else {
		$j("#reg_2").hide();
	}
});

Part of HTML

<div  class="wrapper">
<input type = "checkbox" name ="reg1" id ="reg1" />
</div>
<div id="reg_2" class="wrapper">
<span>Nº do registro:</span>
<input id="reg2" name="reg2" type="text" class="input" />
</div>

Script evaluating the reg2 condition:

} else if ($j("#reg1").is(':checked') && $j("reg2").val() == "") {
      $j("#reg2").css({
        "border": '1px solid #ff0000'
      });
      alert("É necessário informar o Registro no MAPA").focus();
      $j("#reg2").keypress(function() {
        $j("#reg2").css('style', '');
      });
      return false;
    }

#reg1 is a checkbox and #reg2 is of type input text, if the reg2 field is empty and reg1 is checked, the function should issue the alert and return false, but it is not happening.

    
asked by anonymous 31.03.2017 / 20:20

1 answer

1

You have to show full script and tb html so we can parse

You can put before or after the alert to uncheck the reg1 field

document.getElementById("reg1").checked = false;
    
31.03.2017 / 21:02