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. Passing an ID to an external .js file

Passing an ID to an external .js file

Scheduled Pinned Locked Moved ASP.NET
questionjavascriptsysadminregexworkspace
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.
  • D Offline
    D Offline
    dwolver
    wrote on last edited by
    #1

    Want to do clienside validation on a textbox control. This textbox can represent two data types depending on an associtate checkbox. So if checkbox is checked the validation should do (a) and if off do (b) In the javascript funtion below I do a getElementForID("chkBox1") However if I want this to be a global routine I don't know what the checkBox would be and preferably I'd like to pass an Integer so I could do multiple validations on this control or others. The "Sender" parameter seems to be my textbox, So question is how do I setup the ClientValidationFuntion property of the validator to pass an integer?   My custom validator is setup like this <asp:CustomValidator ID="lsdCustomVal" ControlToValidate="txtBox1" runat="server"                      ClientValidationFunction= "validateLSDControl"></asp:CustomValidator> in my external js file I have >> function validateLSDControl( sender, args) {       var expr1 = "[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9]";       var expr2 = "[a-z]-[0-9][0-9][0-9]-[A-Z]/[0-9][0-9]";       var x = document.getElementById(sender.controltovalidate);       var chkbox = document.getElementById("chkBox1");       var smsg = "";       if (chkbox.checked) {             var patt1 = new RegExp(expr, "g");             smsg = "expr1 Invalid";       }       else {             var patt1 = new RegExp(nts, "g");             smsg = "expr2 Invalid";       }                   var result = false;       if (x != null) {             var s = x.value;             if (s.match(patt1))             { //                  alert("it worked");                   result = true;                              }      &nb

    M 1 Reply Last reply
    0
    • D dwolver

      Want to do clienside validation on a textbox control. This textbox can represent two data types depending on an associtate checkbox. So if checkbox is checked the validation should do (a) and if off do (b) In the javascript funtion below I do a getElementForID("chkBox1") However if I want this to be a global routine I don't know what the checkBox would be and preferably I'd like to pass an Integer so I could do multiple validations on this control or others. The "Sender" parameter seems to be my textbox, So question is how do I setup the ClientValidationFuntion property of the validator to pass an integer?   My custom validator is setup like this <asp:CustomValidator ID="lsdCustomVal" ControlToValidate="txtBox1" runat="server"                      ClientValidationFunction= "validateLSDControl"></asp:CustomValidator> in my external js file I have >> function validateLSDControl( sender, args) {       var expr1 = "[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9]";       var expr2 = "[a-z]-[0-9][0-9][0-9]-[A-Z]/[0-9][0-9]";       var x = document.getElementById(sender.controltovalidate);       var chkbox = document.getElementById("chkBox1");       var smsg = "";       if (chkbox.checked) {             var patt1 = new RegExp(expr, "g");             smsg = "expr1 Invalid";       }       else {             var patt1 = new RegExp(nts, "g");             smsg = "expr2 Invalid";       }                   var result = false;       if (x != null) {             var s = x.value;             if (s.match(patt1))             { //                  alert("it worked");                   result = true;                              }      &nb

      M Offline
      M Offline
      Member_3259094
      wrote on last edited by
      #2

      if you are using masterpage then you must below code to access asp control like document.getElementById('<%= chkBox1.ClientID%>'); or change the form's default name according you and access the control by FORMNAME.GETELEMENTBYID plz check it.

      Rajeev Kr. Sharma Sr. Software Engineer E-Meditek Solutions Ltd. http://www.emeditek.co.in/

      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