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
CrishPosted May 13, 2010, 3:38 AM
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.
Bryian TanPosted May 12, 2010, 8:49 AM
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
Rashid KhanPosted May 12, 2010, 6:40 AM
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 TanPosted May 11, 2010, 9:54 PM
Include the JavaScript in the master page.
The application can access the function in the JavaScript through the button onClientClick property.