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

Update textarea when textbox focus changes

Status
Not open for further replies.

pce0

Technical User
Jan 27, 2004
16
0
0
Hi,

I have an HTA that displays multiple textbox's for user input and a readonly textarea that I want to display a description of the textbox selected.

What I'm looking for is the code that will allow me to change the contents of the textarea when the textbox focus changes. For example, when textbox1 is on focus the text "this is textbox1" is displayed in the textarea, when textbox2 is on focus the text "this is the second text box" is displayed etc..

Is this possible, if so, does anyone have a code example of this or something simular?

I'm guessing I need to define the textarea text fr each input box somewhere and come up with a routine to change this when the textbox focus changes... ???

Below is the skelaton code to create the textboxs and textarea (this is just for purpose of testing):

<html>
<head>
<script language="vbscript">

sub window_onload

inputboxs=array("box1","box2","box3")

set objform=document.createElement("form")
objform.name="form1"

set objtxtarea=document.createElement("textarea")
objtxtarea.name="textarea1"
objtxtarea.value="description of selected text box"
objtxtarea.rows=10
objtxtarea.style.position="absolute"
objtxtarea.style.left="500px"
objform.appendchild objtxtarea

for each input in inputboxs
set objtxtbox=document.createElement("input")
objtxtbox.type="text"
objtxtbox.name=input
objtxtbox.size="35"
objtxtbox.style.position="absolute"
objtxtbox.style.left="200px"
objform.appendchild objtxtbox
set objbr=document.createElement("br")
objform.appendchild objbr
next

document.getelementsbytagname("body")(0).appendchild objform
end sub

</script>
</head>

<body>
</body>
 
[1] First, you add a sub like this.
[tt]
sub update
set obj=window.event.srcElement
obj.form.getElementsByTagName("textarea")(0).value=obj.value
set obj=nothing
end sub
[/tt]
[2] Before the appendchild objtxtbox, you add this line.
[tt]
'etc
objtxtbox.style.left="200px"
[blue]objtxtbox.attachEvent "onblur",getref("update")[/blue]
objform.appendchild objtxtbox
'etc
[/tt]
 
Ok, many thanks for the advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top