Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

Please Give Me A Suitable Example Of TextBox Validation . If my Textbox Is Null Then Msg Show The Specific Text box Is Null Its Be Required Filed Using Java Script Code..

Thanks
Posted
Comments
Baji Jabbar 30-Sep-10 3:34am    
Why you are going for JavaScript when we have required field validater, that would be safe , Users can disable JavaScript in their browser and we cannot bi-pass that.
Johnny J. 30-Sep-10 3:39am    
Cool, all words are capitalized - that's better than writing entirely in lower case, anyway...

Example:

<script language="JavaScript" type="text/javascript">

function EmptyChecker(sender, args) {
var value = args.Value;
if(value=="")
{
args.IsValid = false;
alert("Blank");
}
else
args.IsValid = true;
}

</script>



<asp:textbox id="txtDateOfBirth1" runat="server" xmlns:asp="#unknown" />

<asp:customvalidator id="cbDateTime" runat="server" display="None" errormessage="" xmlns:asp="#unknown">
ForeColor="Red" ValidationGroup="group1" ControlToValidate="txtDateOfBirth1"
ClientValidationFunction="EmptyChecker">

<asp:linkbutton id="lbNext1" runat="server" cssclass="btn_next" onclick="lbNext1_Click" xmlns:asp="#unknown">
ValidationGroup="group1">
 
Share this answer
 
v2
Ok, its not working means what.. any error you getting..

function ValidateNow()
 {
   if (document.getElementById('<%=txtbox1.ClientID%>').value == "")
   {
        alert("TextBox is Blank!");
        document.getElementById('<%=txtbox1.ClientID%>').focus();
        return false;
   }
    return true;
}

On Page Load

 Button1.Attributes.Add("onclick", "javascript:if(ValidateNow()==false) {return}; ")
 
Share this answer
 
v2
Comments
Hiren solanki 30-Sep-10 4:52am    
Minor edit for 'pre' tags.
Probaly write this JS.

var a = document.getElementById('your textbox id').value;
if(a != null && a != "")
{

}


Please vote and Accept Answer if it Helped.
 
Share this answer
 
It's not working. The Required Field Validator is very heavy
 
Share this answer
 
v3
Comments
Suthish Nair 30-Sep-10 3:40am    
Now from where Required Filed Validator come from?

You asking for showing message box or want to do with validator controls.

Both are different. Please explain your query properly..
hiii


Im My case I use a TextBox (Text1),On the onclick event it checks the Text1
is null or not with the help of js



XML
<html>
<head>
<script type="text/javascript">
function show()
{
var a=document.getElementById("Text1").value;
if(a=="")
{
 alert('Please enter some values in it');
}
}
</script>

</head>
<body>
<input type="text" id="Text1" onclick="show()"  />
</body>

</html>
 
Share this answer
 
v3
Comments
jindi123 13-Oct-10 3:41am    
it's not working
u have another code

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