Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Why does this not fully work? <Textarea> + DIV + InnerHTML

Reply
Thread Tools

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

 
 
SaraLeePerson@gmail.com
Guest
Posts: n/a
 
      10-26-2007
<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?

 
Reply With Quote
 
 
 
 
Good Man
Guest
Posts: n/a
 
      10-26-2007
wrote in news:1193408017.649249.158790
@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.

 
Reply With Quote
 
 
 
 
Harlan Messinger
Guest
Posts: n/a
 
      10-26-2007
wrote:
> <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.
 
Reply With Quote
 
Doug Miller
Guest
Posts: n/a
 
      10-26-2007
In article < .com>, wrote:
><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.

Observe what happens when you type 123<backspace>4<shift>.
That should be instructive.

> 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>

--
Regards,
Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-26-2007
Doug Miller wrote:
> wrote:
>> <form name=theform>

>
> 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:

<form action="..." name="theform">

>> <textarea onkeydown

>
> onKeyDown


Both are correct in HTML, the former is recommended there and required in XHTML.

>> [...]
>> <div id=divtag></div>

>
> id="divtag"


See above.

>> <script>


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

<script type="text/javascript">


F'up2 alt.html

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
getsanjay.sharma@gmail.com
Guest
Posts: n/a
 
      10-26-2007
On Oct 26, 8:52 pm, spamb...@milmac.com (Doug Miller) wrote:
> In article <1193408017.649249.158...@y42g2000hsy.googlegroups .com>, SaraLeePer...@gmail.com wrote:
> ><form name=theform>

>
> name="theform"
>
> ><textarea onkeydown

>
> 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...

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-26-2007
wrote:
> On Oct 26, 8:52 pm, spamb...@milmac.com (Doug Miller) wrote:
>> [...] SaraLeePer...@gmail.com wrote:
>>> <form name=theform>

>> name="theform"
>>
>>> <textarea onkeydown

>> onKeyDown

>
> Isn't HTML itself case insensitive?


Regarding element type identifiers and attribute names, yes.

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


Then you have not searched enough:

http://www.w3.org/TR/REC-html40/intr...t.html#h-3.2.2


F'up2 alt.html

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$>
 
Reply With Quote
 
getsanjay.sharma@gmail.com
Guest
Posts: n/a
 
      10-26-2007
On Oct 26, 8:52 pm, spamb...@milmac.com (Doug Miller) wrote:
> In article <1193408017.649249.158...@y42g2000hsy.googlegroups .com>, SaraLeePer...@gmail.com wrote:
> ><form name=theform>

>
> name="theform"
>
> ><textarea onkeydown

>
> 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...

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does this not fully work? <Textarea> + DIV + InnerHTML SaraLeePerson@gmail.com Javascript 8 10-26-2007 05:58 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
xhtml, innerHtml, appendChild, and innerHTML. what is the exact proper way to do this with DOM sonic Javascript 5 07-11-2006 08:17 AM
Why does IE not load page fully? easygoin.net HTML 12 09-08-2005 04:33 PM
NS/FF don't change div offsetWidth when div innerHTML is added toand div becomes wider mscir Javascript 3 06-26-2005 04:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57