AngularAngularAngular
AngularAngularAngular

Reputation: 3769

Removing novalidate to a particular field

How can i remove the property of required to the Second Element "Second Name" ?

Here is my Code :

<form action="#" novalidate>
  First Name:
       <input type="text" name="first" required>
  Second Name : 
       <input type="text" name="second" required>
  <input type="submit">
</form>

Upvotes: 0

Views: 3178

Answers (5)

Anders Anderson
Anders Anderson

Reputation: 433

you can use the

removeAttribute command:

First set ID's for the inputs.

I set it to the same value as the name.

Next removeAttribute

document.getElementById("class").removeAttribute("required"); 

This should do the trick ;)

Here, have a fiddle:

Fiddle

Upvotes: 1

Pete
Pete

Reputation: 58432

Using jQuery you can do:

$('input[name=second]').prop('required', false);

Example

Upvotes: 2

Jai
Jai

Reputation: 74738

Try this:

$('input[type="text"][name="second"]').prop('required', false);

it just removes the required property on the target element which has the name "second".

Upvotes: 1

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18873

Try using .removeAttr().

$('input[name="class"]').removeAttr('required')

Upvotes: 1

asdf_enel_hak
asdf_enel_hak

Reputation: 7640

You can set required property to false

$("input[name=class]").prop("required", false);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
Name: <input type="text" name="name" required>
Class: <input type="text" name="class" required>
<input type="submit">
</form>

Upvotes: 3

Related Questions