Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Javascript validation for required fields

Javascript validation for required fields

Scheduled Pinned Locked Moved ASP.NET
javascripthelp
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajiya
    wrote on last edited by
    #1

    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

    C S 2 Replies Last reply
    0
    • R Rajiya

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      R 1 Reply Last reply
      0
      • R Rajiya

        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

        S Offline
        S Offline
        Sandeep Akhare
        wrote on last edited by
        #3

        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... "

        N 1 Reply Last reply
        0
        • C Christian Graus

          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 )

          R Offline
          R Offline
          Rajiya
          wrote on last edited by
          #4

          Hi Thanks a lot for ur solution. It's working fine wen i used the getElementById. Riz

          1 Reply Last reply
          0
          • S Sandeep Akhare

            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... "

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            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

            S M 2 Replies Last reply
            0
            • N N a v a n e e t h

              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

              S Offline
              S Offline
              Sandeep Akhare
              wrote on last edited by
              #6

              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... "

              1 Reply Last reply
              0
              • N N a v a n e e t h

                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

                M Offline
                M Offline
                mohantfor net
                wrote on last edited by
                #7

                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:(

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups