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

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

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,267
    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:
    543
    =?Utf-8?B?cm9kY2hhcg==?=
    Nov 22, 2005
  3. Nathan Sokalski
    Replies:
    4
    Views:
    4,660
    Nathan Sokalski
    Mar 11, 2006
  4. Replies:
    2
    Views:
    1,763
    Roedy Green
    Jan 6, 2006
  5. Anthony Papillion

    TkInter bind() event is not firing event trigger

    Anthony Papillion, Jun 23, 2010, in forum: Python
    Replies:
    3
    Views:
    2,210
    rantingrick
    Jun 23, 2010
  6. 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:
    381
    Nathan Sokalski
    Mar 11, 2006
  7. LilAndy23

    onKeyPress event Mozilla

    LilAndy23, Oct 12, 2005, in forum: Javascript
    Replies:
    10
    Views:
    317
  8. Wescotte

    onkeypress event problem

    Wescotte, Apr 11, 2006, in forum: Javascript
    Replies:
    2
    Views:
    209
Loading...