Write a code for "RequiredFieldValidator" in java script

Answers were Sorted based on User's Feedback



Write a code for "RequiredFieldValidator" in java script..

Answer / rajikiran

function validate()
{
if(document.getElementById("NameId").value == null)
alert("Please enter the name");
document.getElementById("NameId").focus();
return false;
}

or

function validate()
{
with(document.formname)
{
txtboxid.value == ""
alert("Please enter value");
txtboxid.focus();
return false;
}
}

or we can use

document.form.txtboxid.value

instead of

document.getElementById("NameId").value


regards
rajikiran

Is This Answer Correct ?    7 Yes 3 No

Write a code for "RequiredFieldValidator" in java script..

Answer / manoj

suppose the id of the field required to be validated is
NameId

Thus:-

function validate()
{
if(document.getElementById("NameId").value == null)
alert("Please enter the name");
}

Is This Answer Correct ?    5 Yes 3 No

Write a code for "RequiredFieldValidator" in java script..

Answer / amit patel

function validate()
{
if(document.getElementById('<%=Name.ClientID%>').value
== "")
alert("Please enter the name");
document.getElementById("Name").focus();
return false;
}

Is This Answer Correct ?    2 Yes 0 No

Write a code for "RequiredFieldValidator" in java script..

Answer / jayamala

function validate()
{
if(document.getElementById("NameId").value =="")
alert("Please enter the name");
document.getElementById("NameId").focus();
return false;
}

Is This Answer Correct ?    4 Yes 4 No

Write a code for "RequiredFieldValidator" in java script..

Answer / sudhakar sakthivel

function validate()
{
if(document.getElementById("NameId").value == null ||
document.getElementById("NameId").value.trim()=="")
alert("Please enter the name");
document.getElementById("NameId").focus();
return false;
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More ASP.NET Interview Questions

To match the two different controls which control would we use ?

2 Answers   Siebel,


Why is the standalone environment only useful during the development process?

0 Answers  


What are the various ways of securing a web site that could prevent from hacking etc ?

1 Answers  


If Instancing = Single use for ActiveX Exe, how will this be executed if there are 2 consecutive client requests ?

0 Answers   DELL,


how we can solve machine key error in asp.net?

3 Answers  


What is the name of the base class that all web forms will be inherited?

7 Answers  


How to deploy/publish webservices?How many ways?Plz explain me

0 Answers   TCS,


Which library is used by the testers and developers to develop automated tests and create testing tools?

0 Answers  


Where can I get the details on migration of existing projects using various technologies to asp.net?

0 Answers  


what is webservices ? and what is web server ?

1 Answers   Wipro,


what is view stat how it is use ?

2 Answers   Amazon,


When was asp.net released?

0 Answers  


Categories