How to add the ‘required’ attribute to input box using jquery

The required attribute is a boolean attribute.

When present, it specifies that an input field must be filled out before submitting the form to create dynamic required attribute to see below example.

Note: The required attribute works with the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file.

Some PHP Code using ajax to response html page and jquery generate dynamic required attribute/

$i = 0;
while ($row = mysqli_fetch_assoc($query))
		<td style="text-transform: capitalize;">'.$row['document_name'].'</td>
		<td width="10%">
			<input  type="file" id='.$i.' class="requireddocument"  name="carproof'.$i.'" ></td>
		<input id="requireddoc'.$i.'" type="text" class="form-control datepicker" name="expiry_date_car'.$i.'" >

Jquery change event

	 var id = $(this).attr('id');

Leave a Reply

Your email address will not be published. Required fields are marked *