Click here to Skip to main content
14,579,188 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have tried the following code for required field validator
I do not get the appropriate validation message.
I have enclosed the input element in my


Any help is highly appreciated

What I have tried:

<form id="newrentalform">
    <div class="form-group">
        <label>Customer</label>
        <div class="tt-container">
            <input id="customer" required type="text" value="" class="form-control"/>
         </div>
    </div>
</form>
Posted
Updated 30-Jun-20 21:42pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

Please try below code i checked and working on y page i checked by running it locally
<form id="newrentalform">
    <div class="form-group">
        <label>Customer</label>
        <div class="tt-container">
            <input id="customer" required type="text" value="" class="form-control" />
        </div>
    </div>
    <input id="customer"  type="submit" value="Subit" class="form-control" />
</form>
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Same question asked and I have answered there -

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)




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