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. Client Side Validations using .js file

Client Side Validations using .js file

Scheduled Pinned Locked Moved ASP.NET
csharpjavascripthelp
8 Posts 3 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.
  • K Offline
    K Offline
    kvsreedhar
    wrote on last edited by
    #1

    any one over here help me please . I using a .js file for client side validations. Ihave written the validation function in th .js file and when I click the button it has to validate the control(TextBox).But it is not working . I am able to go into the .js file but the code (if condition) is not executed. I give my code as below (C#) Validations.js function validate() { window.alert(".js File"); // I am able to get this alert but if // condition is not checked when textbox is null if(document.getElementById ("<%=txtName.ClientID %>").value=="") { window.alert("Name Feild can not be blank"); document.getElementById("<%=txtName.ClientID%>").focus(); return false; } } Validate.aspx ; when i click on the button without entering a value into the textbox i am not getting the alert message "Name Feild can not be blank". please help me. :) Kovuru Sreedhar :)

    I A 2 Replies Last reply
    0
    • K kvsreedhar

      any one over here help me please . I using a .js file for client side validations. Ihave written the validation function in th .js file and when I click the button it has to validate the control(TextBox).But it is not working . I am able to go into the .js file but the code (if condition) is not executed. I give my code as below (C#) Validations.js function validate() { window.alert(".js File"); // I am able to get this alert but if // condition is not checked when textbox is null if(document.getElementById ("<%=txtName.ClientID %>").value=="") { window.alert("Name Feild can not be blank"); document.getElementById("<%=txtName.ClientID%>").focus(); return false; } } Validate.aspx ; when i click on the button without entering a value into the textbox i am not getting the alert message "Name Feild can not be blank". please help me. :) Kovuru Sreedhar :)

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      kvsreedhar wrote:

      f(document.getElementById ("<%=txtName.ClientID %>").value=="")

      Why dont you try like this?

      if(document.getElementById ('txtName').value=='')

      please don't forget to vote on the post that helped you.

      K 1 Reply Last reply
      0
      • I Imran Khan Pathan

        kvsreedhar wrote:

        f(document.getElementById ("<%=txtName.ClientID %>").value=="")

        Why dont you try like this?

        if(document.getElementById ('txtName').value=='')

        please don't forget to vote on the post that helped you.

        K Offline
        K Offline
        kvsreedhar
        wrote on last edited by
        #3

        :rose:Thanks Imran it's working.:rose: But a small doubt , when I used the same code as an InLine code (in .aspx script tag and did not use .js file), it worked . what's the concept behind. please clear my doubt Thanks in advance

        Kovuru Sreedhar

        I 1 Reply Last reply
        0
        • K kvsreedhar

          :rose:Thanks Imran it's working.:rose: But a small doubt , when I used the same code as an InLine code (in .aspx script tag and did not use .js file), it worked . what's the concept behind. please clear my doubt Thanks in advance

          Kovuru Sreedhar

          I Offline
          I Offline
          Imran Khan Pathan
          wrote on last edited by
          #4

          kvsreedhar wrote:

          But a small doubt , when I used the same code as an InLine code (in .aspx script tag and did not use .js file), it worked . what's the concept behind.

          Problem was that you have put txtName.ClientID in double quote so that It was worked as string.

          please don't forget to vote on the post that helped you.

          modified on Monday, August 4, 2008 3:04 AM

          K 1 Reply Last reply
          0
          • I Imran Khan Pathan

            kvsreedhar wrote:

            But a small doubt , when I used the same code as an InLine code (in .aspx script tag and did not use .js file), it worked . what's the concept behind.

            Problem was that you have put txtName.ClientID in double quote so that It was worked as string.

            please don't forget to vote on the post that helped you.

            modified on Monday, August 4, 2008 3:04 AM

            K Offline
            K Offline
            kvsreedhar
            wrote on last edited by
            #5

            I have tried but not working ( .js code) if(document.getElementById('+<%txtName.ClientID%>+').value=='') { window.alert("Name Feild can not be blank"); return false; }

            Kovuru Sreedhar

            I 1 Reply Last reply
            0
            • K kvsreedhar

              I have tried but not working ( .js code) if(document.getElementById('+<%txtName.ClientID%>+').value=='') { window.alert("Name Feild can not be blank"); return false; }

              Kovuru Sreedhar

              I Offline
              I Offline
              Imran Khan Pathan
              wrote on last edited by
              #6

              kvsreedhar wrote:

              I have tried but not working

              Yeah.It didn't work. Sorry,I modified my previous post

              please don't forget to vote on the post that helped you.

              1 Reply Last reply
              0
              • K kvsreedhar

                any one over here help me please . I using a .js file for client side validations. Ihave written the validation function in th .js file and when I click the button it has to validate the control(TextBox).But it is not working . I am able to go into the .js file but the code (if condition) is not executed. I give my code as below (C#) Validations.js function validate() { window.alert(".js File"); // I am able to get this alert but if // condition is not checked when textbox is null if(document.getElementById ("<%=txtName.ClientID %>").value=="") { window.alert("Name Feild can not be blank"); document.getElementById("<%=txtName.ClientID%>").focus(); return false; } } Validate.aspx ; when i click on the button without entering a value into the textbox i am not getting the alert message "Name Feild can not be blank". please help me. :) Kovuru Sreedhar :)

                A Offline
                A Offline
                Ajeet mittal
                wrote on last edited by
                #7

                in place of document.getElementById("<%=txtName.ClientID%>").focus(); u write document.getElementById('<%=txtName.ClientID%>').focus(); this will work perfectly.

                K 1 Reply Last reply
                0
                • A Ajeet mittal

                  in place of document.getElementById("<%=txtName.ClientID%>").focus(); u write document.getElementById('<%=txtName.ClientID%>').focus(); this will work perfectly.

                  K Offline
                  K Offline
                  kvsreedhar
                  wrote on last edited by
                  #8

                  thank you for your help and time.

                  Kovuru Sreedhar

                  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