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. Character count problem..

Character count problem..

Scheduled Pinned Locked Moved ASP.NET
questionjavascripthelp
3 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.
  • W Offline
    W Offline
    waddie1
    wrote on last edited by
    #1

    Hey all I've got an aspx page that has a number of text boxes on it. I have the following javascript function that counts characters within the text box: function myLength(lbl,tb,max){ //lbl is the ID of the control that displays the count //tb is the ID of the control that is being counted //max is the maximum amount of characters allowed in the control lbl.innerHTML = tb.innerHTML.length + " of " + max; } Within the vb page associated to the aspx page I have the following code: txtTitle.Attributes.Add("OnKeyUp", "myLength(document.getElementById('" _ + lblWC_Title.ClientID + "'),document.getElementById('" + _ txtTitle.ClientID + "')," + txtTitle.MaxLength.ToString + ")") This adds the onkeyup event to the text box and passes the correct client ID's into the javascript function. Now my problem is this, if my asp text box is multiline then the word count works fine but nothing happens if it is a text box set to be single line. I use the same methods as shown above for both types of text box. Any ideas on what is causing this? Thanks in advance W.:)

    G 1 Reply Last reply
    0
    • W waddie1

      Hey all I've got an aspx page that has a number of text boxes on it. I have the following javascript function that counts characters within the text box: function myLength(lbl,tb,max){ //lbl is the ID of the control that displays the count //tb is the ID of the control that is being counted //max is the maximum amount of characters allowed in the control lbl.innerHTML = tb.innerHTML.length + " of " + max; } Within the vb page associated to the aspx page I have the following code: txtTitle.Attributes.Add("OnKeyUp", "myLength(document.getElementById('" _ + lblWC_Title.ClientID + "'),document.getElementById('" + _ txtTitle.ClientID + "')," + txtTitle.MaxLength.ToString + ")") This adds the onkeyup event to the text box and passes the correct client ID's into the javascript function. Now my problem is this, if my asp text box is multiline then the word count works fine but nothing happens if it is a text box set to be single line. I use the same methods as shown above for both types of text box. Any ideas on what is causing this? Thanks in advance W.:)

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Have you examined the code that is created (e.g. view source in browser), to see what is missing?

      --- b { font-weight: normal; }

      W 1 Reply Last reply
      0
      • G Guffa

        Have you examined the code that is created (e.g. view source in browser), to see what is missing?

        --- b { font-weight: normal; }

        W Offline
        W Offline
        waddie1
        wrote on last edited by
        #3

        Sorry for taking so long to reply, didnt email me like it said it would. The problem is solved, it was because a textbox with multiline selected is rendered as textarea which has both innerHTML and innerTEXT where as a single line text box does not have either of these. Instead changing the .innerHTML or .innerTEXT to simply '.value' solved the problem. Thanks for replying.

        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