/    Sign up×
Community /Pin to ProfileBookmark

deleting rows on keypress delete

hi, please help me with my problem… i need to delete a row after (left) clicking on it and then pressing the delete button on the keyboard. I can already do the part where the row catches my (left) click but after that, i don’t know how to use the delete button.. how do i do it? i also already have the code for deleting the row but I can’t call it unless I know how to call on delete. thanks! hoping for your help…thank you!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzOct 19.2006 — I don't think there's a cross-browser way to differentiate the "." and "del" keys -- they both seem to show as 46 in JavaScript for the onkeypress event. The onkeydown and onkeyup events show different things in different browsers.

[url=http://www.quirksmode.org/js/events_properties.html#key]Use onkeypress to detect the key.[/url]
Copy linkTweet thisAlerts:
@superchritchauthorOct 19.2006 — Thanks! I used onkeyup event, however, i can't seem to pass a variable or an argument to my function. this is what i have:

//where row is the row I want to delete

function checkRow (row, event)

{

if (window.event.button == 2)

{*rightclick code*}

//left click code

else if (window.event.button == 1) {

if( document.captureEvents && event.KEYUP ) {

document.captureEvents( event.KEYUP );

}

document.onkeyup = doSomething;

}

}

function doSomething (e){

var code;

if (!e) var e = window.event;

if (e.keyCode) code = e.keyCode;

else if (e.which) code = e.which;

var character = String.fromCharCode(code);

alert('Character was ' + character);

}

this works, that is, i'm getting the keycode that i want to, but i want to also pass the row variable that i have from check row so i could do deleteRow (row.rowIndex) in doSomething but when i do this:

document.onkeyup = doSomething (row);

...

function doSomething (row, e) {

...

alert('Character was ' + character);

}

the keycode i always get is the one for left click and i don't get to press delete anymore after my alert. why is that? how do i solve this? thank you very much!
Copy linkTweet thisAlerts:
@KravvitzOct 19.2006 — Where did you get the code for the checkRow function?

document.captureEvents() is for NS4.x only. Also "event.KEYUP" should be "Event.KEYUP", if you really want to support a browser that old.
Copy linkTweet thisAlerts:
@superchritchauthorOct 19.2006 — actually checkrow came from me. that was my code before. how do i do this? i can't seem to pass the variable that i need.
Copy linkTweet thisAlerts:
@KorOct 19.2006 — Something like this?
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="txt/javascript"&gt;
&lt;script type="text/javascript"&gt;
var dRow=[];
function markRows(r){
r.style.background='#CCCCCC';
dRow[dRow.length]=r;
}
function deleteRows(){
var i=0, r
while(r=dRow[i++]){
r.parentNode.removeChild(r)
}
dRow=[];
}
onload=function(){
var rows=document.getElementById('tab').getElementsByTagName('tr');
var i=0, r
while(r=rows[i++]){
r.onclick=function(){markRows(this)}
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table width="400" border="1" cellspacing="1" cellpadding="1" id="tab"&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br&gt;
&lt;br&gt;
&lt;input type="button" value="Delete Row(s)" onclick="deleteRows()"&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@superchritchauthorOct 19.2006 — thank you! got it already!
×

Success!

Help @superchritch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...