Javascript validation for required fields
-
Hi, I am having a login form. I am validating if the userid id and password is blank and returing a boolean value in javascript. If userid is not specified then i am giving an alert and setting the focus back to txtUserid textbox. but it throws a javascript error saying document.frmLogin.txtuserid is null or not an object. Am sending the code.Plz check where i am going wrong. function fValidate() { if (document.frmLogin.txtUserid.value == "" && document.frmLogin.txtPassword.value != "") { alert("User Id must be specified !"); //document.frmLogin.txtUserId.focus(); return false; } else if (document.frmLogin.txtUserid.value != "" && document.frmLogin.txtPassword.value == "") { alert("Password must be specified !"); document.frmLogin.txtPassword.value = "" document.frmLogin.txtPassword.focus(); return false; } else if (document.frmLogin.txtUserid.value == "" && document.frmLogin.txtPassword.value == "") { alert("User Id and Password must be specified !"); //document.frmLogin.txtUserId.focus(); document.frmLogin.txtPassword.focus(); return false; } else return true; } Thanks, Riz
-
Hi, I am having a login form. I am validating if the userid id and password is blank and returing a boolean value in javascript. If userid is not specified then i am giving an alert and setting the focus back to txtUserid textbox. but it throws a javascript error saying document.frmLogin.txtuserid is null or not an object. Am sending the code.Plz check where i am going wrong. function fValidate() { if (document.frmLogin.txtUserid.value == "" && document.frmLogin.txtPassword.value != "") { alert("User Id must be specified !"); //document.frmLogin.txtUserId.focus(); return false; } else if (document.frmLogin.txtUserid.value != "" && document.frmLogin.txtPassword.value == "") { alert("Password must be specified !"); document.frmLogin.txtPassword.value = "" document.frmLogin.txtPassword.focus(); return false; } else if (document.frmLogin.txtUserid.value == "" && document.frmLogin.txtPassword.value == "") { alert("User Id and Password must be specified !"); //document.frmLogin.txtUserId.focus(); document.frmLogin.txtPassword.focus(); return false; } else return true; } Thanks, Riz
Apparently, document.frmLogin.txtUserid doesn't work. Is this ASP.NET ? I assume so. If so, you need to write your client side user Ids into a var and then use those and document.getElementByID to find the controls you want. Your server side control names are not passed through to the client side, check out the source of yuor page and you will see.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi, I am having a login form. I am validating if the userid id and password is blank and returing a boolean value in javascript. If userid is not specified then i am giving an alert and setting the focus back to txtUserid textbox. but it throws a javascript error saying document.frmLogin.txtuserid is null or not an object. Am sending the code.Plz check where i am going wrong. function fValidate() { if (document.frmLogin.txtUserid.value == "" && document.frmLogin.txtPassword.value != "") { alert("User Id must be specified !"); //document.frmLogin.txtUserId.focus(); return false; } else if (document.frmLogin.txtUserid.value != "" && document.frmLogin.txtPassword.value == "") { alert("Password must be specified !"); document.frmLogin.txtPassword.value = "" document.frmLogin.txtPassword.focus(); return false; } else if (document.frmLogin.txtUserid.value == "" && document.frmLogin.txtPassword.value == "") { alert("User Id and Password must be specified !"); //document.frmLogin.txtUserId.focus(); document.frmLogin.txtPassword.focus(); return false; } else return true; } Thanks, Riz
Why don;'t you use Required field validator instead of having bulk of javascirpt code
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Apparently, document.frmLogin.txtUserid doesn't work. Is this ASP.NET ? I assume so. If so, you need to write your client side user Ids into a var and then use those and document.getElementByID to find the controls you want. Your server side control names are not passed through to the client side, check out the source of yuor page and you will see.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Why don;'t you use Required field validator instead of having bulk of javascirpt code
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Sandeep Akhare wrote:
Why don;'t you use Required field validator instead of having bulk of javascirpt code
Is required validator is browser specific ?? What about in firefox and opera ?
Navaneeth My Website
-
Sandeep Akhare wrote:
Why don;'t you use Required field validator instead of having bulk of javascirpt code
Is required validator is browser specific ?? What about in firefox and opera ?
Navaneeth My Website
Navaneeth. wrote:
Is required validator is browser specific
yes if the user is working with a browser that supports DHTML :)it should work
Navaneeth. wrote:
What about in firefox and opera ?
It works for Firefox regarding Opera i don't know
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Sandeep Akhare wrote:
Why don;'t you use Required field validator instead of having bulk of javascirpt code
Is required validator is browser specific ?? What about in firefox and opera ?
Navaneeth My Website
hai i used textbox with autopostback true, as well as i used tab index sequentialy.while i press tab the cursor not goto the next textbox. plz help:(