I need to show and hide a form based on a checkbox (default off), making the form input and it's label hidden, plus not required. Right now, I'm just trying to sort out the display issues. I know I can disable the form with code like this:
$(document).ready(function() {
$('#00NU00000049YHZ').change(function(){
$('#company').prop('disabled' $('#companylbl').hide();, !$(this).is(':checked' $('#companylbl').show()));
});
});
</script>
Sample of HTML form where I want the Company field to hide/show via a check box and also set it as required or not required depending on the state of the check box during later validation.
<!DOCTYPE html>
<html lang="en">
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"> </META>
<HEAD>
</HEAD>
<BODY>
<form id="w2lForm"
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
This is for a Company:<input id="00NU00000049YHZ" name="00NU00000049YHZ" type="checkbox" value="0" /><br>
<label id="cmpnylbl" for="company">Company</label><input id="company" maxlength="40" name="company" size="20" type="text" /><br>
<label for="street">Address</label><textarea id="street" name="street"></textarea><br>
<input type="submit" name="submit">
</form>
</BODY>
</HTML>
I'm using jQuery 1.11.1. Among lots of other things, I've tried putting a DIV tag around the Company Label and Input fields, then doing an add/remove class where the visibility was either "visible" or "hidden", but that didn't seem to work to hide the text for "Company" along with the input text field. Could someone please tell me what I need to do?
$('#company').prop("disabled" $('#companylbl').hide();, !$(this).is(':checked' $('#companylbl').show()));not sure how this would work, surely it just throws syntax error in the console?