javascript - Disable inputs if checkbox is checked -
i have ticket purchase form. have fill peronal information there. possible buy empty ticket, without name on it. requires clicking on checkbox, makes input fields disabled. var inputsdisabled = 0;
$("#three").change(function(){ if(inputsdisabled == 0){ $("input[name=fname]").attr("disabled", true); $("input[name=lname]").attr("disabled", true); $("input[name=email]").attr("disabled", true); $("input[name=sponsor]").attr("disabled", true); $("input[name=phone]").attr("disabled", true); inputsdisabled = 1; } else{ $("input[name=fname]").attr("disabled", false); $("input[name=lname]").attr("disabled", false); $("input[name=email]").attr("disabled", false); $("input[name=sponsor]").attr("disabled", false); $("input[name=phone]").attr("disabled", false); inputsdisabled = 0; } });
when buys empty ticket , presses "back" browser button, gets form. mentioned checkbox still checked automatically fields not disabled anymore. tried use code below doesnt help.
if ("#three".checked) { $("input[name=fname]").attr("disabled", true); $("input[name=lname]").attr("disabled", true); $("input[name=email]").attr("disabled", true); $("input[name=sponsor]").attr("disabled", true); $("input[name=phone]").attr("disabled", true); }
is there better way this?
i think if condition should this
if($("#three").is(":checked")) { $("input[name=fname]").attr("disabled", true); $("input[name=lname]").attr("disabled", true); $("input[name=email]").attr("disabled", true); $("input[name=sponsor]").attr("disabled", true); $("input[name=phone]").attr("disabled", true); }
Comments
Post a Comment