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

Discussion in 'HTML' started by SaraLeePerson@gmail.com, Oct 26, 2007.

  1. Guest

    <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? :)
    , Oct 26, 2007
    #1
    1. Advertising

  2. Good Man Guest

    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.
    Good Man, Oct 26, 2007
    #2
    1. Advertising

  3. 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.
    Harlan Messinger, Oct 26, 2007
    #3
  4. Doug Miller Guest

    In article <>, 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.
    Doug Miller, Oct 26, 2007
    #4
  5. 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
    Thomas 'PointedEars' Lahn, Oct 26, 2007
    #5
  6. Guest

    On Oct 26, 8:52 pm, (Doug Miller) wrote:
    > In article <>, 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...
    , Oct 26, 2007
    #6
  7. wrote:
    > On Oct 26, 8:52 pm, (Doug Miller) wrote:
    >> [...] 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/intro/sgmltut.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$>
    Thomas 'PointedEars' Lahn, Oct 26, 2007
    #7
  8. Guest

    On Oct 26, 8:52 pm, (Doug Miller) wrote:
    > In article <>, 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...
    , Oct 26, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. easygoin.net

    Why does IE not load page fully?

    easygoin.net, Sep 7, 2005, in forum: HTML
    Replies:
    12
    Views:
    1,251
    easygoin
    Sep 8, 2005
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,844
    Smokey Grindel
    Dec 2, 2006
  3. mscir
    Replies:
    3
    Views:
    307
    Martin Honnen
    Jun 26, 2005
  4. Replies:
    8
    Views:
    154
  5. Sandy Tipper

    Why does textarea.value= not work

    Sandy Tipper, Mar 23, 2008, in forum: Javascript
    Replies:
    12
    Views:
    192
    Rich Grise
    May 22, 2008
Loading...

Share This Page