Question on onkeypress or keyCode event trigger

Discussion in 'Javascript' started by AwefulService@gmail.com, Feb 29, 2008.

  1. Guest

    Hi,

    I attempt to create HTML ordered or unordered list function here.
    Start with IE7...

    function addList(obj,lt) {
    var theBody = document.getElementById(obj);
    var ul = document.createElement(lt);
    theBody.appendChild(ul);

    var li = document.createElement('li');
    ul.appendChild(li);

    var keyCode = event.keyCode;
    // if (obj.type == "keydown" || obj.keyCode == 13)
    if (keyCode == 13 || document.onkeypress) {
    theBody.ul.appendChild(li);
    return false;
    }

    }


    <form action="" method="post">
    Data entry:</br>
    <textarea name="stuff" cols="60" rows="8"></textarea><br/>
    <input type="button" value="Add unordered list"
    onClick="addList('stuff','ul');"><br/>
    <input type="button" value="Add ordered list"
    onClick="addList('stuff','ol');"> <br/>
    <input type="reset" value="reset">
    </form>

    What am I doing wrong?

    Thanks.
     
    , Feb 29, 2008
    #1
    1. Advertising

  2. Guest

    On Feb 29, 12:46 pm, wrote:
    > Hi,
    >
    > I attempt to create HTML ordered or unordered list function here.
    > Start with IE7...
    >
    > function addList(obj,lt) {
    > var theBody = document.getElementById(obj);
    > var ul = document.createElement(lt);
    > theBody.appendChild(ul);
    > var li = document.createElement('li');
    > ul.appendChild(li);


    Probably I should have made this part clearer, the following code
    block did not work,
    care to explain why and how to fix it? thks.

    > var keyCode = event.keyCode;
    > // if (obj.type == "keydown" || obj.keyCode == 13)
    > if (keyCode == 13 || document.onkeypress) {
    > theBody.ul.appendChild(li);
    > return false;
    > }

    // block ends

    >
    > }
    >



    > <form action="" method="post">
    > Data entry:</br>
    > <textarea name="stuff" cols="60" rows="8"></textarea><br/>
    > <input type="button" value="Add unordered list"
    > onClick="addList('stuff','ul');"><br/>
    > <input type="button" value="Add ordered list"
    > onClick="addList('stuff','ol');"> <br/>
    > <input type="reset" value="reset">
    > </form>
    >
    > What am I doing wrong?
    >
    > Thanks.
     
    , Feb 29, 2008
    #2
    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. Marvin Massih

    "Keycode DLL not found or invalid keycode"

    Marvin Massih, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,161
    Marvin Massih
    Dec 31, 2004
  2. =?Utf-8?B?cm9kY2hhcg==?=

    onkeypress event

    =?Utf-8?B?cm9kY2hhcg==?=, Nov 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    445
    =?Utf-8?B?cm9kY2hhcg==?=
    Nov 22, 2005
  3. Nathan Sokalski
    Replies:
    4
    Views:
    4,270
    Nathan Sokalski
    Mar 11, 2006
  4. Replies:
    2
    Views:
    1,661
    Roedy Green
    Jan 6, 2006
  5. Nathan Sokalski

    Determining the Browser and event.keyCode vs. event.which

    Nathan Sokalski, Mar 10, 2006, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    193
    Nathan Sokalski
    Mar 11, 2006
Loading...

Share This Page