Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  70] [ 3]  / answers: 1 / hits: 16034  / 11 Years ago, fri, january 24, 2014, 12:00:00

I working in Asp.net c#. I have a task to clear multiple textbox on button click, but now according to the requirement I have to use JAVASCRIPT. So I can't do that with C# code.
Now I am using the following :



JAVASCRIPT Function :



function clrCtrl() {
document.getElementById('TextBox1').value = ;

}


with this method the line of is greater. Now when I have 20 30 of textbox this code is not efficient so plz give me any suggestion to this....


More From » html

 Answers
15

Give class name to the text box to which you want to clear then try to use



document.getElementsByClassName(MyTestClass) to get elements and use your logic to do whatever you want.



eg:-



function clrCtrl() {

var elements = [] ;
elements = document.getElementsByClassName(MyTestClass);

for(var i=0; i<elements.length ; i++){
elements[i].value = ;
}

}


Hope this helps.



Kind Regards.


[#72967] Thursday, January 23, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reedmustafam

Total Points: 211
Total Questions: 83
Total Answers: 105

Location: Vanuatu
Member since Wed, Oct 14, 2020
4 Years ago
;