Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
whenever i clicked the submit button the txtbox contains something in that,if i submit the button when txtbox is empty alert will come with text of text box is not empty and also textbox values are unique (avoiding duplicates) in the database

What I have tried:

html




Features_Name:



javascript

$(document).ready(function () {
$('.submit').attr('disabled', true);
$('#txtName').keyup(function () {
if ($.trim($(this).val.length != 0)) {
$('.submit').attr('disabled', false);
}
else if ($.trim($('#txtName').val.length =="0")) {
alert('Features_Name is not empty');
}
else {
$('.submit').attr('disabled', true);
}

})
})
Posted
Updated 1-Jan-17 20:00pm

1 solution

For client-side validation, check out this demo:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#myForm").submit(function(){
	  var isValid = true;
  
	  if($("#txtName").val().trim().length == 0) {
		  isValid = false;
		alert("Name cannot be empty!");
  
	  }
	  return isValid;
  });
});
</script>
</head>
<body>

<form id="myForm" action="#" method="post">

<input type="text" id="txtName">

<input type="submit" value="Send">

</form>

</body>
</html>
JSFiddle[^]

As regards to:
Quote:
textbox values are unique (avoiding duplicates) in the database
That can only be done on the server-side by checking the value against the database content.
 
Share this answer
 
v2
Comments
Devaraneni Laxman Rao 2-Jan-17 3:30am    
thanq u for replay sir
Devaraneni Laxman Rao 2-Jan-17 3:59am    
Sir,when i am inserting the data into the database the data inserted when set the debug point(break point) and not inserted with out break point please tell me what is the reason.
Peter Leow 2-Jan-17 4:07am    
How would you expect me to diagnose something with one statement like that? Neither do I have access to your computer nor your screen. Suggest you post it as a new question with more details.
Last but not least, if a solution helped you to solve a specific problem that you have posted, do mark it as solution. Take stock of your previous questions too.

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



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