How to find asp controls on page at client side(run time)?
-
I have to add reset function in my project which will be called on every page and it will find out all the asp controls of a page at run time and reset them. Can any on help me in this.............. (I need this using JavaScript)
-
I have to add reset function in my project which will be called on every page and it will find out all the asp controls of a page at run time and reset them. Can any on help me in this.............. (I need this using JavaScript)
You can use something like this.
function Reset() { var inputs = document.getElementsByTagName('input'); var textareas = document.getElementsByTagName('textarea'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].type && inputs[i].type.toLowerCase()=='text') { inputs[i].value=''; } } for (var i = 0; i < textareas.length; i++) { textareas[i].value=''; } }
-
You can use something like this.
function Reset() { var inputs = document.getElementsByTagName('input'); var textareas = document.getElementsByTagName('textarea'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].type && inputs[i].type.toLowerCase()=='text') { inputs[i].value=''; } } for (var i = 0; i < textareas.length; i++) { textareas[i].value=''; } }
Thanks a lot Costica, I am able to reset TextBoxes but not DropDown using this code, can you please help in this. -- modified at 3:21 Wednesday 18th October, 2006
-
Thanks a lot Costica, I am able to reset TextBoxes but not DropDown using this code, can you please help in this. -- modified at 3:21 Wednesday 18th October, 2006
This is the updated function:
function Reset()
{
var inputs = document.getElementsByTagName('input');
var textareas = document.getElementsByTagName('textarea');
var lists = document.getElementsByTagName('select');
for (var i = 0; i < inputs.length; i++)
{
if (inputs[i].type && inputs[i].type.toLowerCase()=='text')
{
inputs[i].value='';
}
}
for (var i = 0; i < textareas.length; i++)
{
textareas[i].value='';
}
for (var i = 0; i < lists.length; i++)
{
lists[i].selectedIndex =-1;
}
} -
This is the updated function:
function Reset()
{
var inputs = document.getElementsByTagName('input');
var textareas = document.getElementsByTagName('textarea');
var lists = document.getElementsByTagName('select');
for (var i = 0; i < inputs.length; i++)
{
if (inputs[i].type && inputs[i].type.toLowerCase()=='text')
{
inputs[i].value='';
}
}
for (var i = 0; i < textareas.length; i++)
{
textareas[i].value='';
}
for (var i = 0; i < lists.length; i++)
{
lists[i].selectedIndex =-1;
}
}Thanks again Costica, I have to add one more functionality to reset radioButton as well as checkBoxes to this function please help in this.