Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Question on onkeypress or keyCode event trigger

Reply
Thread Tools

Question on onkeypress or keyCode event trigger

 
 
AwefulService@gmail.com
Guest
Posts: n/a
 
      02-29-2008
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.
 
Reply With Quote
 
 
 
 
AwefulService@gmail.com
Guest
Posts: n/a
 
      02-29-2008
On Feb 29, 12:46 pm, (E-Mail Removed) 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.


 
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
Determining the Browser and event.keyCode vs. event.which Nathan Sokalski ASP .Net 4 03-11-2006 06:36 AM
Determining the Browser and event.keyCode vs. event.which Nathan Sokalski ASP .Net Building Controls 4 03-11-2006 06:36 AM
OnKeyPress event doesn't work in netscape? jrice@berkshire-aap.com Java 2 01-06-2006 04:24 PM
onkeypress event =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 0 11-22-2005 02:01 AM
"Keycode DLL not found or invalid keycode" Marvin Massih ASP .Net 0 12-31-2004 05:40 PM



Advertisments