Question on onkeypress or keyCode event trigger

A

AwefulService

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

AwefulService

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top