0

I have included jquery file and following HTML

<script src="jquery-1.7.js"></script>

HTML:

<form action="http://www.google.com" onSubmit="return validate();">
        <input type="text" required="true" name="URL" >
        <input type="submit" value="Submit">
</form> 

When i submit form with empty field give the message "Please fill out the field" but if i write wrong URL i didn't find any message and form submit.

How can i do URL validation?

4
  • i have also added latest jquery file <script src="code.jquery.com/jquery-1.11.0.min.js"></script> Commented Jul 15, 2014 at 9:08
  • Please post the code in your validate() function. Also, you only need one version of jQuery. Commented Jul 15, 2014 at 9:09
  • You're looking for something like this: jqueryvalidation.org ? Commented Jul 15, 2014 at 9:11
  • Dipak Thanks. My problem has been solved from your idea. Commented Jul 15, 2014 at 9:42

1 Answer 1

1

1 : You are using type="text" ... So why would it give you error when you are entering wrong url. For that use doctype for HTML5 and mention your input as follows,

<input type="url" required="required" name="URL" />

2 : Please check your validate() function. You must return false, if it does not satify your condition, in order to stop the form being submitted.

Adding suggestion from Akki619... You don't even need a single javascript for validation as HTML5 does everything for you. Find the awesomeness of HTML5 http://www.the-art-of-web.com/html/html5-form-validation/

Sign up to request clarification or add additional context in comments.

1 Comment

just to add to dipak's answer here is the link for detail the-art-of-web.com/html/html5-form-validation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.