Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html required attribute set as not required

Tags:

html

webforms

I have some code as below:

<label class="control-label col-sm-4" for="datepicker">Date of Birth</label>
<div class="col-sm-8" ><input class="form-control col-sm-10" type="text" id="datepicker" name="datepicker" required="true" value="<?php if(isset($_SESSION['DOB'])) echo $_SESSION['DOB'] ?>"></div>

My issue is that I don't want this "Date of Birth" field to be a required field anymore. How do I set this field as unrequired?

I have tried setting required="false" but this does not work.

Any advice much appreciated, many thanks Jean-Claude

like image 870
Jeanclaude Avatar asked May 09 '26 13:05

Jeanclaude


2 Answers

The required attribute does not take the attribute value. It's just required="true", or required="required", or just setting the

<input type="text" required />

would make it required as well. Just unset the required attribute. If you're trying to unset it after some user action (with javascript) then use the .removeAttribute("required") function.

like image 118
Luka Kvavilashvili Avatar answered May 12 '26 03:05

Luka Kvavilashvili


<label class="control-label col-sm-4" for="datepicker">Date of Birth</label>
<div class="col-sm-8" ><input class="form-control col-sm-10" type="text" id="datepicker" name="datepicker" value="<?php if(isset($_SESSION['DOB'])) echo $_SESSION['DOB'] ?>"></div>

Avoid using required if you don't need them.

Also the attributes that are not necessary must be avoided.

like image 30
Vivek Tankaria Avatar answered May 12 '26 04:05

Vivek Tankaria



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!