hello friends
i have a project. where i have several form in that.
using master page and each content page have form, now i want to check client side that user cannot leave blank nd cannot give wrong values in form. so i create functions , file main is validate.js. here i create funcations of each form, now i want to call it on content page, how to attached this file so that i can all desired function of particuler form. please tell me where and how to attached that js file and how call functions on button event
thanks
Loading

Bryian TanRank #396 · 6.3K reputationPosted May 11, 2010, 5:54 PM EDT
Include the JavaScript in the master page.
The application can access the function in the JavaScript through the button onClientClick property.
Rashid Khan152 reputationPosted May 12, 2010, 2:40 AM EDT
function NewUser()
{
var FirstName = document .getElementById("txtFirstName").value;
var LastName = document.getElementById("txtLastName").value;
var UserName= document.getElementById("txtEmailId").value;
var Password= document.getElementById("txtPassword").value;
var ConfirmPassword= document.getElementById("txtRePwd").value;
var SecurityQuestion= document.getElementById("txtSecQuestion").value;
var Answer= document.getElementById("txtSecAnswer").value;
var Address = document.getElementById("txtAddress").value;
var Mobile = document.getElementById("txtMobile").value;
var DOB = document.getElementById("txtBirthDate").value;
//FirstName validation
if(FirstName=='')
{
alert ("Please Enter you First Name");
document.getElementById("txtFirstName").focus();
document.getElementById("txtFisrtName").value="";
return false;
}
//lastName validation
if(FirstName=='')
{
alert ("Please Enter you Last Name");
document.getElementById("txtLastName").focus();
document.getElementById("txtLastName").value="";
return false;
}
//username validation
if(UserName=='')
{
alert("Please Enter User Name");
document.getElementById("txtEmailId").focus();
return false;
}
else
{
if(!UserName.match('^[A-Z-a-z]*$'))
{
alert("User Name must be Alphabates.");
document.getElementById("txtEmailId").focus();
document.getElementById('txtEmailId').value="";
return false;
}
}
//Password validation
if(Password=='')
{
alert("Enter Password");
document.getElementById("txtPassword").focus();
return false;
}
else
{
if(Password.length<6)
{
alert("Password atleast 6 charchters long.");
document.getElementById("txtPassword").focus();
document.getElementById('txtPassword').value="";
return false;
}
}
//confirmPassword validation
if(ConfirmPassword =='')
{
alert("Enter Password Again.");
document.getElementById("txtRePwd").focus();
return false;
}
else
{
if(ConfirmPassword!= Password)
{
if(document.getElementById("txtRePwd").value!=document.getElementById("txtPassword").value)
{
alert("Password should be same");
}
document.getElementById("txtRePwd").focus();
document.getElementById('txtRePwd').value="";
return false;
}
}
// Security question
if(SecurityQuestion =='')
{
alert("Please Enter Security Question");
document.getElementById("txtSecQuestion").focus;
document.getElementById("txtSecQuestion").value="";
return false;
}
//Security Answer
if(Answer=='')
{
alert("Please Enter the Answer");
document.getElementById("txtSecAnswer").focus();
document.getElementById("txtSecAnswer").value="";
return false;
}
//Mobile
if(Mobile =='')
{
alert("Enter Mobile No. Please");
document.getElementById("txtMobile").focus();
return false;
}
else
{
if(Password.length<10)
{
alert("Wrong Number.");
document.getElementById("txtMobile").focus();
document.getElementById("txtMobile").value="";
return false;
}
}
//check Address field
if(Address=='')
{
alert("Please Enter the Address");
document.getElementById("txtAddress").focus();
document.getElementById("txtAddress").value="";
return false;
}
// check Date of birth
if(DOB=='')
{
alert ("Please Enter your DOB ");
document.getElementById("txtBirthDate").focus();
return false;
}
}
this js file i drag nd drop in my master page.
and content.aspx
but script not working
please help me.
Thanks
Bryian TanRank #396 · 6.3K reputationPosted May 12, 2010, 4:49 AM EDT
Make sure all the Textboxes (txtFirstName...txtBirthDate) in content.aspx. Did you see any JavaScript error like (document.getElementById(...) is null)? Also, try var FirstName = document .getElementById("<%=txtFirstName.ClientID %>").value; , repeat the same for the rest of the document .getElementById(...)
Thanks,
Bryian Tan
CrishRank #1,487 · 1.1K reputationPosted May 12, 2010, 11:38 PM EDT
make a javascript function where u can pass all parameters like control name,error string,Is Required.
ex. so when you pass parameters in function TestValidate(txtFirstname , 'first name required', true)
then after you can validate this values in javascript function.