.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

javascript to validate textbox

Posted By: Ramesh     Posted Date: August 09, 2010    Points:2   Category :ASP.Net
My requirement is that i have a webpage with one textbox,submit button.
when ever user doesnt enter any text and clicks submit then he must get an alert box thatis by running javascript written in htmlsource page.
anybody please help me by code or any url's

Regards,
Ramesh



Responses
Author: Sunil Yadav       [Moderator]      
Posted Date: August 09, 2010     Points: 5   

Hi,
check below solution.

if(document.form1.txtName.value=="")
{
alert("Please enter text.");
return false;
}
hope it helps.

Author: Syed Shakeer Hussain             
Posted Date: August 09, 2010     Points: 5   

Hi,
<script type="text/javascript">

function method()
{
if((document.getElementById("txt").value).length == 0)
{
document.getElementById("txt").focus();
alert("The textbox should not be empty");
}
}

</script>
</head>
<body>
<form id="frm">
<input type="text" id="txt" onblur="javascript:method();" />
</form>



Author: willium             
Posted Date: August 09, 2010     Points: 5   

A textbox can be validated using a JavaScript by using a redirection to the JavaScript page ..say I need to check for username then we redirect the form to login.js (JavaScript for the checking) by the action attribute.

___________________________________________________________________________________________________________
Want to get-on Google's first page and loads of traffic to your website? Hire a SEO Specialist from Ocean Groups [url=http://oceangroups.org/]seo pecialist [/url]




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend