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

What are the ways to show data grid inside a data grid for a master details type of tables? If we write any code for DataGrid methods, what is the access specifier used for that methods in the code behind file and why?

0 Answers  


Why does my asp.net file have multiple tag with runat=server?

0 Answers  


What is server side routing?

0 Answers  


what is value type to reference type

6 Answers   AG Technologies, IBM,


Difference between using directive vs using statement?

0 Answers  






Why is it important to maintain session state?

1 Answers  


Describe how ASP.NET maintains process isolation for each Web application?

0 Answers   B-Ways TecnoSoft,


what are partial classes and their use?

3 Answers   Microsoft,


there is two functions function a and function b like fun a(){.... ..... } fun b() { } in function b i write the coding to add two numbers and i need to dispaly the sum result in function a with out using global variable. how we do?

1 Answers  


What is MSIL?

4 Answers  


What's the difference between viewstate and sessionstate?

0 Answers  


What is customer control and user control?

1 Answers   Perot Systems,


Categories