Why does this not fully work? <Textarea> + DIV + InnerHTML

S

SaraLeePerson

<form name=theform>
<textarea onkeydown="whynowork()" ID="inputbox" cols=25 rows=5></
textarea>
</form>

<div id=divtag></div>

<script>
function whynowork(){
document.getElementById("divtag").innerHTML =
document.forms['theform'].elements['inputbox'].value
}
</script>

Hello
Can someone please explain what I am doing wrong here? When you enter
something into the textarea, it skips the first character. How can I
rectify this problem? :)
 
G

Good Man

(e-mail address removed) wrote in @y42g2000hsy.googlegroups.com:
<form name=theform>
<textarea onkeydown="whynowork()" ID="inputbox" cols=25 rows=5></
textarea>
</form>

<div id=divtag></div>

<script>
function whynowork(){
document.getElementById("divtag").innerHTML =
document.forms['theform'].elements['inputbox'].value
}
</script>

Hello
Can someone please explain what I am doing wrong here? When you enter
something into the textarea, it skips the first character. How can I
rectify this problem? :)


why use "onkeydown()"? your function is working (aside from your terrible
HTML that is missing quotes at random).

when the key is going down, there *is* no value in the textarea yet. use
onchange(); or something.
 
H

Harlan Messinger

<form name=theform>
<textarea onkeydown="whynowork()" ID="inputbox" cols=25 rows=5></
textarea>
</form>

<div id=divtag></div>

<script>
function whynowork(){
document.getElementById("divtag").innerHTML =
document.forms['theform'].elements['inputbox'].value
}
</script>

Hello
Can someone please explain what I am doing wrong here? When you enter
something into the textarea, it skips the first character. How can I
rectify this problem? :)

Because there isn't a character until the key has come back up and the
key press has been registered. If you type more than one character, the
display in the divtag div should be one character behind each time. Use
onkeypress.
 
D

Doug Miller

<form name=theform>
name="theform"

<textarea onkeydown
onKeyDown

="whynowork()" ID="inputbox" cols=25 rows=5></
textarea>
</form>

<div id=divtag></div>
id="divtag"

<script>
function whynowork(){
document.getElementById("divtag").innerHTML =
document.forms['theform'].elements['inputbox'].value
}
</script>

Hello
Can someone please explain what I am doing wrong here? When you enter
something into the textarea, it skips the first character.

As you can easily see by typing 12345 in the textarea, it's not the *first*
character that fails to display. Go slowly, and observe when each character
appears.

How can I
rectify this problem? :)

Consider the sequence of events that occurs when a key is pressed, then
evaluate whether onKeyDown is the event handler you're really interested in,
or if another one might be more appropriate. <g>
 
T

Thomas 'PointedEars' Lahn

Doug said:
name="theform"

Attribute-delimiting quotes are not required here in HTML, but recommended.
They are required regardless of the attribute value in XHTML only. More
important is that a required attribute is missing here:

said:
onKeyDown

Both are correct in HTML, the former is recommended there and required in XHTML.
[...]
<div id=divtag></div>

id="divtag"

See above.

The `type' attribute is required for the `script' element.

<script type="text/javascript">


F'up2 alt.html

PointedEars
 
G

getsanjay.sharma

onKeyDown

Isn't HTML itself case insensitive? If this were javascript it makes
sense that we need to write only 'onclick' and nothing else but in
HTML...I guess I am a bit confused here..

Searching the W3C for this sadly didn't yield any results...
 
T

Thomas 'PointedEars' Lahn

G

getsanjay.sharma

onKeyDown

Isn't HTML itself case insensitive? If this were javascript it makes
sense that we need to write only 'onclick' and nothing else but in
HTML...I guess I am a bit confused here..

Searching the W3C for this sadly didn't yield any results...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top