Post by KenHello! I'm kind of new at this but I need a little help. I've created
an HTA application. I'd like to create a text box and then assign
buttons to run vbscripts against whatever is typed into the box. Is
this possible?
Hi Ken,
Here is some code that might help:
--- <code> ---
<HTML>
<HEAD>
<script language="vbscript">
' --- discussion (avoiding that annoying hta "dialog bounce") ---
' this "trick" found on the vbScript ng, code by mikHar, 05Sept06
' Normally, an hta dialog will initially be shown in its "default"
' position and size for a brief instant. Later, when it gets
' around to running your script code, it will move/resize itself
' according to your wishes. Placing the move/resize code AHEAD
' of the hta tag seems to avoid that...
' --- end of discussion ----------------------
Const wdDlg = 500, htDlg = 300 ' dialog size
Const pxLeft = 100, pxTop = 100 ' positioning
window.ResizeTo wdDlg,htDlg
window.MoveTo pxLeft,pxTop
</script>
<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="htaTextBoxIndexingDemo"
WINDOWSTATE="normal" SCROLL = "no" BORDERSTYLE="normal" BORDER="thin"
CAPTION="yes" MAXIMIZEBUTTON="no" MINIMIZEBUTTON="no" ICON="mru.ico"
SHOWINTASKBAR="yes" SINGLEINSTANCE="yes" SYSMENU="yes" VERSION="1.0" >
<TITLE> << (hta) get Textbox via element ID Demo >>
</TITLE>
<SCRIPT LANGUAGE="vbScript">
<!--
' --- description block --------------------------
'
' Title: textbox indexing demo, jw 11Mar08
' Author: mr_unreliable
' Website: none at this time (but lurks around the wsh/vbs ng's)
' Usage: Use at you own risk, tested on win98se...
' --- revision history ---------------------------
' 11Mar08: initial attempt (working from "regular" hta dbDlg)...
' --- end of description block -------------------
Option Explicit
' --- global variables ---------------------------
Dim oDoc ' as document object
' --- end of declarations and constants ----------
' --- INITIALIZATION ROUTINE ---------------------
Sub initDialog()
Const sMe = "[initDialog], "
Set oDoc = window.document
' note: dynamically adding textboxes here...
With oDoc.getElementById("inputBoxes")
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox1 type=text
value='the' </input>"
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox2 type=text
value='quick' </input>"
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox3 type=text
value='brown' </input>"
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox4 type=text
value='fox' </input>"
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox5 type=text
value='jumped' </input>"
End With
End Sub
' ------------------------------------------------
' --- EVENT HANDLERS -----------------------------
' ------------------------------------------------
Sub ShowResults()
Const sMe = "[btnClick], "
Dim sResults ' as string
sResults = "txtBox1 contents: " &
oDoc.getElementById("txtBox1").value & vbCrLf _
& "txtBox2 contents: " &
oDoc.getElementById("txtBox2").value & vbCrLf _
& "txtBox3 contents: " &
oDoc.getElementById("txtBox3").value & vbCrLf _
& "txtBox4 contents: " &
oDoc.getElementById("txtBox4").value & vbCrLf _
& "txtBox5 contents: " & oDoc.getElementById("txtBox5").value
MsgBox sResults, vbInformation, " the textbox contents are... "
window.close()
End Sub
//-->
</SCRIPT>
<style>
body {font-family: ms sans serif; font-size: 10pt; font-weight: 400;
color: Navy;
margin-top: 4px; margin-left: 1px; margin-right: 1px;
margin-bottom: 1px;
height: 10px; width: 10px; border-style: none; }
input {width: 400px}
button {height: 25px; width: 100px; font-family: verdana;
font-weight: 400;
width: 125px; }
h4 {position:absolute; top:250; left: 250;
margin-top: 6px; margin-bottom: 0px; padding-top: 0%;
padding-bottom: 0%;
font-family: Arial; font-size: 8pt; font-weight: Normal;
font-style: Italic;
color: Navy; }
</style>
</HEAD>
<BODY onload="initDialog()" scroll='no' text='navy' bgcolor="silver" >
<CENTER>
<DIV id="inputBoxes" >
</DIV>
<BR><BR><BR><BR><BR> <!-- space down a bit to position button -->
<BUTTON id="btnSubmit" onclick="ShowResults()" >Submit</BUTTON>
</CENTER>
<h4 id="logo" ALIGN=RIGHT > jawar productions (all rights
reserved)... </h4>
</BODY>
</HTML>
--- <end code> ---
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)