Hey everyone I have a relatively simple/newbie question. I have been searching all over Microsoft's VBScript website to find information about the elements object/property. I found one reference from an old book excerpt and even that was not very detailed. Then I also searched on the net but couldn't find anything on the other vbscript sites about it. I came here and found one article about it that Mr. Schulz was nice enough to post but I still have more questions below(after his code).
_____________________________________________________________________________________________________________________________
Here is my favorite method (in vb and java scripts)...
<html>
<script language="javascript">
function ChangeColor(){
var z=document.forms.frmDemo
for (var i=0;i<z.elements.length;i++){
z.elements.style.backgroundColor = "#00FF00"
}
}
</script>
<script language="vbscript">
Sub btn1_OnClick()
Dim fld
For Each fld in document.forms.frmDemo.elements
fld.style.backgroundcolor = "#FF0000"
Next
End Sub
</script>
<body>
<form id=frmDemo>
<input type=text id=txt1><br>
<input type=text id=txt2><br>
<input type=text id=txt3><br>
<input type=text id=txt4><br>
<input type=text id=txt5><br>
<input type=button id=btn1 value="Click me">
<input type=button id=btn2 value="Click me too" onClick="ChangeColor();">
</form>
</body>
</html>
Hope it helps,
Rob
Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
_____________________________________________________________________________________________________________________________
Questions:
1. In the example does "fld" represent a HTML control that is stored in an array?
2. How can I find what type of control the loop is iterating at currently?
3. Are "elements" an object or property in the For Each example above?
4. Can someone point me to a website that has more info about controlling HTML controls programmatically especially with an emphasis about the elements ojbect/property?
Thanks in advance for all of your help or suggestions.
David
davrem_2000@yahoo.com
_____________________________________________________________________________________________________________________________
Here is my favorite method (in vb and java scripts)...
<html>
<script language="javascript">
function ChangeColor(){
var z=document.forms.frmDemo
for (var i=0;i<z.elements.length;i++){
z.elements.style.backgroundColor = "#00FF00"
}
}
</script>
<script language="vbscript">
Sub btn1_OnClick()
Dim fld
For Each fld in document.forms.frmDemo.elements
fld.style.backgroundcolor = "#FF0000"
Next
End Sub
</script>
<body>
<form id=frmDemo>
<input type=text id=txt1><br>
<input type=text id=txt2><br>
<input type=text id=txt3><br>
<input type=text id=txt4><br>
<input type=text id=txt5><br>
<input type=button id=btn1 value="Click me">
<input type=button id=btn2 value="Click me too" onClick="ChangeColor();">
</form>
</body>
</html>
Hope it helps,
Rob
Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
_____________________________________________________________________________________________________________________________
Questions:
1. In the example does "fld" represent a HTML control that is stored in an array?
2. How can I find what type of control the loop is iterating at currently?
3. Are "elements" an object or property in the For Each example above?
4. Can someone point me to a website that has more info about controlling HTML controls programmatically especially with an emphasis about the elements ojbect/property?
Thanks in advance for all of your help or suggestions.
David
davrem_2000@yahoo.com