1

Hi I'm using a form on my website and the required attribute seems not working on mobile it works perfectly on my browser. Does anyone have an issue with jquery, javascript or node package ?

<form action="myaction" method = "post" enctype="multipart/form-data">
    <input type="text" id="name" pattern= .{2,} required />
    <input type="file" id="user_picture" required />
    <input type="submit" />
</form>

On mobile even if I fill any fields, it submit but nothing is add to my database. I just want to find a way to print somme error message.

anonym
  • 259
  • 4
  • 17

2 Answers2

1

Input's attribute "required" is html5 attribute not jQuery functionality. Here you have link and if you scroll down you can see browser support where you can check it. If your browser does not support this attribute you can use one of jQuery library for handle it.

Franky238
  • 511
  • 5
  • 21
  • Yeah but the problem is that the page get refreshed either way, I want an alternative solution to output error messages. Do you know any ? – anonym May 11 '16 at 09:20
  • You have to create condition where you have to check $('input["required"]').val() if is on example not match pattern then your javascript function have to return false – Franky238 May 11 '16 at 09:41
  • you can use on example this [plugin](https://jqueryvalidation.org/category/plugin/) – Franky238 May 11 '16 at 09:42
1

You can use jquery validation https://jqueryvalidation.org/ and how to use it is also mentioned in this link : A simple jQuery form validation script

Community
  • 1
  • 1
Akash Amin
  • 2,741
  • 19
  • 38