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. Problum In Javascript

Problum In Javascript

Scheduled Pinned Locked Moved ASP.NET
javascripttools
9 Posts 2 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.
  • S Offline
    S Offline
    Sachin Dubey
    wrote on last edited by
    #1

    Hi All My Friends, I Have 2 problems in a javascript. 1: I am not getting the Item Count Of Dropdown List. 2: I am calling javascript on Button "OnClientClick" event,then also onclick event is fired even script returning false. Hav a look on Script function validate() { if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex == 0) { alert("Select a Category name !") document.getElementById("<%=ddlCategories.ClientID%>").focus() return false; } else if (document.getElementById("<%=txtText.ClientID%>").value == "") { alert("Please fill the Message field !") document.getElementById("<%=txtText.ClientID%>").focus() return false; } else { if (SubcategoryCount > 0) { if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex != 0 && document.getElementById("<%=ddlSubCategories.ClientID%>").selectedIndex == 0) { alert("Select a Sub-Category name !") return false; } } } }

    A 1 Reply Last reply
    0
    • S Sachin Dubey

      Hi All My Friends, I Have 2 problems in a javascript. 1: I am not getting the Item Count Of Dropdown List. 2: I am calling javascript on Button "OnClientClick" event,then also onclick event is fired even script returning false. Hav a look on Script function validate() { if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex == 0) { alert("Select a Category name !") document.getElementById("<%=ddlCategories.ClientID%>").focus() return false; } else if (document.getElementById("<%=txtText.ClientID%>").value == "") { alert("Please fill the Message field !") document.getElementById("<%=txtText.ClientID%>").focus() return false; } else { if (SubcategoryCount > 0) { if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex != 0 && document.getElementById("<%=ddlSubCategories.ClientID%>").selectedIndex == 0) { alert("Select a Sub-Category name !") return false; } } } }

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #2

      Sachin Dubey wrote:

      if (SubcategoryCount > 0) {

      Where you got this SubcategoryCount from?:confused: Its good if you can make your code little bit readable to the forum readers. :)

      Arun Jacob http://codepronet.blogspot.com/

      S 1 Reply Last reply
      0
      • A Arun Jacob

        Sachin Dubey wrote:

        if (SubcategoryCount > 0) {

        Where you got this SubcategoryCount from?:confused: Its good if you can make your code little bit readable to the forum readers. :)

        Arun Jacob http://codepronet.blogspot.com/

        S Offline
        S Offline
        Sachin Dubey
        wrote on last edited by
        #3

        That is only i asked in first question.. I Have ddlSubCategories in Page

        A 1 Reply Last reply
        0
        • S Sachin Dubey

          That is only i asked in first question.. I Have ddlSubCategories in Page

          A Offline
          A Offline
          Arun Jacob
          wrote on last edited by
          #4

          Sachin Dubey wrote:

          That is only i asked in first question

          that i know. :) What i am asking is, in your code you have a line of code like,SubcategoryCount>0, Whats SubcategoryCount?Is it a global variable?How you are assigning value for that?

          Arun Jacob http://codepronet.blogspot.com/

          S 1 Reply Last reply
          0
          • A Arun Jacob

            Sachin Dubey wrote:

            That is only i asked in first question

            that i know. :) What i am asking is, in your code you have a line of code like,SubcategoryCount>0, Whats SubcategoryCount?Is it a global variable?How you are assigning value for that?

            Arun Jacob http://codepronet.blogspot.com/

            S Offline
            S Offline
            Sachin Dubey
            wrote on last edited by
            #5

            That is not any Variable...That is just i written... But I want to Use ddlSubcategories.Items.Count in place of SubCategoryCount.. But I Am not Getting the value... Actually if user doesnt select category then Select Category alert will Prompt..If User Selected Category And There is no Subcategory of that then we allow him to proceed...But if that category has some Sub Categories then its must to Select SubCategory... Thats what i Want in Else Condition u see...

            A 1 Reply Last reply
            0
            • S Sachin Dubey

              That is not any Variable...That is just i written... But I want to Use ddlSubcategories.Items.Count in place of SubCategoryCount.. But I Am not Getting the value... Actually if user doesnt select category then Select Category alert will Prompt..If User Selected Category And There is no Subcategory of that then we allow him to proceed...But if that category has some Sub Categories then its must to Select SubCategory... Thats what i Want in Else Condition u see...

              A Offline
              A Offline
              Arun Jacob
              wrote on last edited by
              #6

              Sachin Dubey wrote:

              That is not any Variable...That is just i written...

              How we know its simply written. :) Ok.Try ddlSubCategory.options.length

              Arun Jacob http://codepronet.blogspot.com/

              S 1 Reply Last reply
              0
              • A Arun Jacob

                Sachin Dubey wrote:

                That is not any Variable...That is just i written...

                How we know its simply written. :) Ok.Try ddlSubCategory.options.length

                Arun Jacob http://codepronet.blogspot.com/

                S Offline
                S Offline
                Sachin Dubey
                wrote on last edited by
                #7

                Thanks Arun I Got The count By : if (document.getElementById("<%=ddlSubCategories.ClientID%>").options.length > 1) Now its showing the message also...But Its Saving the record ... My Code of Button is: After reading that script it reading On_click event Code... How to Tackele that..

                A 1 Reply Last reply
                0
                • S Sachin Dubey

                  Thanks Arun I Got The count By : if (document.getElementById("<%=ddlSubCategories.ClientID%>").options.length > 1) Now its showing the message also...But Its Saving the record ... My Code of Button is: After reading that script it reading On_click event Code... How to Tackele that..

                  A Offline
                  A Offline
                  Arun Jacob
                  wrote on last edited by
                  #8

                  Sachin Dubey wrote:

                  OnClientClick="javascript:validate();"

                  Instead try this, OnClientClick="return validate();"

                  Arun Jacob http://codepronet.blogspot.com/

                  S 1 Reply Last reply
                  0
                  • A Arun Jacob

                    Sachin Dubey wrote:

                    OnClientClick="javascript:validate();"

                    Instead try this, OnClientClick="return validate();"

                    Arun Jacob http://codepronet.blogspot.com/

                    S Offline
                    S Offline
                    Sachin Dubey
                    wrote on last edited by
                    #9

                    Hey Arun... It Works... Thanks A Lot.... :)

                    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