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. Implement common JS to Textboxes

Implement common JS to Textboxes

Scheduled Pinned Locked Moved Web Development
javascripthtmlregexquestion
2 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.
  • K Offline
    K Offline
    ketan bader
    wrote on last edited by
    #1

    Hi, all I am using a JS for validation of HTML Tags in textboxes. I have 15 textbox control to validate.. can someone tell me how can i use a common JS for all textboxes, because giving textboxid of all controls to "getElementById()"is not possible.. I am using the following JS. function tagValidate() { str=(document.getElementById ('htmltag')).value; if(str.match(/([\<])([^\>]{1,})*([\>])/i)==null) alert("There is no HTML Tags Found"); else alert("HTML Tags Found"); } Regards.

    P 1 Reply Last reply
    0
    • K ketan bader

      Hi, all I am using a JS for validation of HTML Tags in textboxes. I have 15 textbox control to validate.. can someone tell me how can i use a common JS for all textboxes, because giving textboxid of all controls to "getElementById()"is not possible.. I am using the following JS. function tagValidate() { str=(document.getElementById ('htmltag')).value; if(str.match(/([\<])([^\>]{1,})*([\>])/i)==null) alert("There is no HTML Tags Found"); else alert("HTML Tags Found"); } Regards.

      P Offline
      P Offline
      Perspx
      wrote on last edited by
      #2

      ketan bader wrote:

      because giving textboxid of all controls to "getElementById()"is not possible..

      Why not..? Can't you call them textbox1, textbox2.. etc and then loop through and call your function on each one..? If you don't do this, you could assign the textboxes in question a class name that no other element on your page has, then do something like:

      //Find all input elements
      var inputs = document.getElementsByTagName("input");

      for(var i=0;i<inputs.length;++i) {
      //Check whether the input element is a textbox that you want to validate
      if(inputs[i].type=="text"&&inputs[i].className=="validatetextbox") {
      //Do validation on textbox here
      }
      }

      Regards, --Perspx

      "A refund for defective software might be nice, except it would bankrupt the entire software industry in the first year."
      -Andrew Tanenbaum
      "Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer."
      -Fred Brooks

      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