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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

programatically add controls to HTA 1

Status
Not open for further replies.

mrmovie

Technical User
Oct 2, 2002
3,094
GB
Hi all,
i have seen a few examples of creating controls in a HTA by creating a text string then setting the .InnerHTML property to the text.
Does anyone have any samples of doing it through 'code', e.g.
Set newCheckBox = New Checkbox
hta.document.addcontrol(newCheckBox)
etc
Thanks,

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
It is usually made using dom method. I can show a quick sketch of an hta submit to result in a google search resultant page. I use radio button instead of checkbox because it fits in the picture (querystring) better. Checkbox works similarly; but radio button has an oddity in the detail (as you see) in the constructor to make it work which checkboxes do not suffer from. Other details in the construction may be helpful too.
[tt]
<html>
<head>
<hta:application id="htaid" />
<script type="text/vbscript" language="vbscript">
sub doit
dim oform, otext, osubmit
set oform=document.formname
set otext=document.createelement("input")
with otext
.type="text"
.value="Aristophanes"
.name="q"
end with

set osubmit=document.createelement("input")
with osubmit
'no name, if you need one, name it anything other than "submit"
.type="submit"
.value="submit"
end with

with oform
.appendChild otext
.appendChild document.createelement("br")
.appendChild osubmit
.appendChild document.createelement("br")
.action="[ignore][/ignore]"
.method="get"
.attachEvent "onsubmit", getRef("doexit")
end with
set osubmit=nothing
set otext=nothing

dim a, aa 'same dimension
a=array("lang_en","lang_fr","lang_el")
aa=array("English","French","Greek")

dim oradio
for i=0 to ubound(a)
'this does not work for radio
'set oradio=document.createelement("input")
'radio button's oddity
'for ie, must include both type and name, no less in the constructor.
set oradio=document.createelement("<input type='radio' name='lr'>")
with oradio
.value=a(i)
end with
with oform
.appendChild oradio
.appendchild document.createTextNode(aa(i))
.appendchild document.createElement("br")
end with
set oradio=nothing
next
set oform=nothing

dim ogen
set ogen=document.getElementById("generator")
ogen.parentNode.removeChild ogen
set ogen=nothing

end sub

sub doexit
self.close
end sub
</script>
</head>
<body>
<form name="formname" id="formid">
</form>
<button id="generator" onclick="doit" language="vbscript">do it</button><br />
</body>
</html>
[/tt]
 
thanks tsuji

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top