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

Why is it preferred to not use finalize for clean up?

0 Answers  


What is view state and use of it ?

1 Answers  


Can action method static?

0 Answers  


What is difference Data List and Data Repeater Control ?

1 Answers   TCS,


For which does this Codebehind="MyCode.aspx.cs" is relevent to ?

0 Answers   Siebel,


Describe briefly what is the role of IIS on an ASP.NET application? What does it for the same application?

0 Answers   InfoAxon Technologies,


what do you mean software devlopment ?

9 Answers   HCL,


What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?

4 Answers  


Explain one critical mapping?

0 Answers  


Your manager has asked you to describe what you would use application variables for. What statement best describes the use of application variables? a) Application Variables are used to keep state for each connected user. b) Application Variables are used to keep state for the web site c) Application Variables are used to keep state for the application on the server d) Application Variables are used to keep state for all applications objects in the web site.

1 Answers   Syntax Softtech,


What is the difference between ASP Session State and ASP.Net Session State?

0 Answers  


Whats MSIL, and why should my developers need an appreciation of it if at all?

3 Answers   Siebel,


Categories