Click here to Skip to main content
14,576,812 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am having a simple html form with the required validator set to one of its input field, but I do not get the validation message
Can you please help where am I going wrong??

What I have tried:

This is my code

<form id="newrentalform">
    <div class="form-group">
        <label>Customer</label>
        <div class="tt-container">
            <input id="customer" name="customer" type="text" class="form-control" required>
         </div>
    </div>

    <div class="form-group">
        <label>Movie</label>
        <div class="tt-container">
            <input id="movie" name="movie" type="text" value="" class="form-control">
        </div>
    </div>

    <div class="row">
        <div class="col-md-4">
            <ul id="movies" class="list-group"></ul>
        </div>
    </div>

   

    <button  class="btn btn-primary">Submit</button>
</form>




I have tried a demo with the required atribute it works in the demo but fails in case of the above code
Posted
Updated 5 days ago
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I presume that customer input is the element you are talking about.

Javascript will return a message if no value has been added, maybe why it does not work in your sample as the java code was not copied over. With the required field, it will only show a small pop-up at the element that says required in Chrome, no messages at all.

<pre><button class="btn btn-primary" onclick="validateme();">Submit</button>


<pre><script type="text/javascript">
		function validateme() { 
			var customer = document.getElementById('customer');

			if (customer.length == 0 && customer.value == "") {
				alert('No valid customer added.');
				document.getElementById('customer').focus();
}
</script>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100