Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to refer to web controls by their id attribute

Status
Not open for further replies.

akwatters

Programmer
Jul 30, 2004
1
GB
Given the following example html
Code:
<input name="test1" type="checkbox" value="test1"/>
<input name="test2" type="checkbox" value="test2"/>

I can refer to a web control by
Code:
Browser("xxx").Page("yyy").WebCheckBox("test1").Set "ON"

However, with the following html
Code:
<input id="id1" name="test" type="checkbox" value="test1"/>
<input id="id2" name="test" type="checkbox" value="test2"/>

How can I do the same thing?
 
Hello akwatters,

Maybe getElementByID() would suit your need. A demo is like this.
Code:
<html>
<head>
<title>checkbox id</title>
<script language=vbscript>
sub id1_checking
    document.getElementByID("id2").checked=(not document.getElementByID("id1").checked)
end sub
sub id2_checking
    document.getElementByID("id1").checked=(not document.getElementByID("id2").checked)
end sub
</script>
<body>
<form>
<input id="id1" name="test" type="checkbox" value="test1" onclick="id1_checking">test1</input><br>
<input id="id2" name="test" type="checkbox" value="test2" onclick="id2_checking">test2</input><br>
</form>
</body>
</html>
regards - tsuji
 
-Amendments-

By mindless habit, should [1] not put the closing tag for input; and [2] forget to close the head-tag. Hence the relisting of the demo is this:
Code:
<html>
<head>
<title>checkbox id</title>
<script language=vbscript>
sub id1_checking
    document.getElementByID("id2").checked=(not document.getElementByID("id1").checked)
end sub
sub id2_checking
    document.getElementByID("id1").checked=(not document.getElementByID("id2").checked)
end sub
</script>
</head>
<body>
<form>
<input id="id1" name="test" type="checkbox" value="test1" onclick="id1_checking">test1<br>
<input id="id2" name="test" type="checkbox" value="test2" onclick="id2_checking">test2<br>
</form>
</body>
</html>
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top