Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

HTML
<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

Please try below code i checked and working on y page i checked by running it locally
C#
<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>
 
Share this answer
 
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>
 
Share this answer
 

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

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900