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