0

I use the code below to add required attribute to the inputs in a form and its working perfectly but want to remove required attribute for only the input type:URL in the form.

$('#private-acc').click(function(){
   $('#private-office').css('display', 'block');
   $('#private-office :input').prop('required', true); 

   $('#public-office').css('display', 'none');   
   $('#public-office :input').prop('required', false);
});

Please how do i do it, I don't have any idea at all.

1 Answers1

1

You can remove it using:

$("input[type=url]").removeAttr("required");

Refer to this question for more discussion. The only change you need here is the selector input[type=url].

Using .prop:

$("input[type=url").prop('required', false);
31piy
  • 23,323
  • 6
  • 47
  • 67
  • Tried but its not working, The required is been added by jquery only when the form is selected. but wants to disable the required attribute for only the URL input cos not everyone has a website. – Ebby S. V. Hesse Jan 02 '18 at 04:40
  • @EbbyS.V.Hesse -- where is the form, and how it gets selected? Please add all the relevant information in the question. – 31piy Jan 02 '18 at 04:43
  • @31piy---I have 2 forms (css- display: none;) with a RADIO buttton, when either a PRIVATE form is selected by a radio button, then the form appears and the required attribute is added to all the input fields. – Ebby S. V. Hesse Jan 02 '18 at 04:52
  • @EbbyS.V.Hesse -- okay, then you need to execute the code in my answer after all the `required` attributes are set, but just before you show the form. – 31piy Jan 02 '18 at 05:01