Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Input-Attribute "required" only for one button

Tags:

html

I've got an file-input which is submitted with a submit button. But theres also a delete button in the same form. So my problem is, when i press the delete button it will say "Please select an file" because the "required" attribute is in the file-input. I want that this message only displays when you press the upload button(of course only if the input is empty).

Here's my Code :

<form>
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">
<input type="submit" name="del_image" value="Delete">
</form>
like image 972
frosty Avatar asked Oct 23 '25 01:10

frosty


1 Answers

You could use formnovalidate attribute to skip validation on specific submit button:

<form>
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">
<input type="submit" name="del_image" value="Delete" formnovalidate >
</form>
like image 98
TPAKTOPA Avatar answered Oct 25 '25 14:10

TPAKTOPA



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!