/    Sign up×
Community /Pin to ProfileBookmark

add an row attribute

Hi all

Im adding rows dynamically to my table (‘ksa’) !
But i would like to add an attribute for the row i’m adding..see below code

<style>
.classover {background-color: white;}
.classout {background-color: blue;}
</style>

function insRow(){

var newRow=document.getElementById(‘ksa’).insertRow(0)

var cell0=newRow.insertCell(0)
var cell1=newRow.insertCell(1)
var cell2=newRow.insertCell(2)
var cell3=newRow.insertCell(3)
var cell4=newRow.insertCell(4)
var cell5=newRow.insertCell(5)

cell0.innerHTML=cntr
cell0.style.display = “none”;

cell1.innerHTML=document.getElementById(‘grpnr’).value;
cell1.style.display = “none”;
cell2.innerHTML=document.getElementById(‘nr’).value;
cell2.style.display = “none”;
cell3.innerHTML=document.getElementById(‘txtantal’).value;
cell4.innerHTML=”stk”;

cell5.innerHTML=document.getElementById(‘beskrv’).value;
—————————————————————–


Here im trying to add this row attribute….keep getting an syntax error
—————————————————————–

newRow(0).innerHTML ='<onmouseOver=”this.className=’classover ‘” onmouseOut=”this.className=’classout'”>’;

}

hope somebody can help me…..thanks ?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 03.2005 — Let's re-write the code in DOM 2 level style:

[code=php]
function insRow(){
var txt =[];
txt[0] ='cntr';
txt[1] = document.getElementById('grpnr').value;
txt[2] = document.getElementById('nr').value;
txt[3] = document.getElementById('txtantal').value;
txt[4] = 'stk';
txt[5] = document.getElementById('beskrv').value;
var root = document.getElementById('ksa').getElementsByTagName('tr')[0].parentNode;
var oTr = document.createElement('tr');
for(var i=0;i<txt.length;i++){
var oTd = createEE('td');
oTd.appendChild(document.createTextNode(txt[i]));
if(i<3){createAA(oTd,'display','none','style')}
oTr.appendChild(oTd);
}
oTr.onmouseover=function(){this.className='classover'}
oTr.onmouseout=function(){this.className='classout'}
root.appendChild(oTr)
}
function createEE(el){
this.obj=document.createElement(el);
return this.obj;
}
function createAA(obj,att,val,type){
if(type=='style'){obj.style[att]=val}
else{obj.setAttribute(att,val)}
return
}
</script>
[/code]


But I don't get it... Why you need a display none... Well, it might be your need, after all
Copy linkTweet thisAlerts:
@me2authorNov 03.2005 — 

Hi thanks....
-----------------------------------


KOR

I hope you will support Romania join EU
-----------------------------------


Yes in denmark we do
Copy linkTweet thisAlerts:
@me2authorNov 03.2005 — Hi

by the way...

if(i<3){createAA(oTd,'display','none','style')}

i got 17 cols in total ...what do i do when i dont want display col 9 ,12 ,16

and 17 to

I have just shorten the above code a bit

Thanks Kor
Copy linkTweet thisAlerts:
@KorNov 03.2005 — Anyway, to attach an event to an object you may use:

[I]object[/I].on[I]someevent[/I] = somefunction;

or, if parameters needed (or more functions to be fired or other codelines)

[I]object[/I].on[I]someevent[/I] = [B]function(){[/B]somefunction('param');someotherfunction()[B]}[/B]
Copy linkTweet thisAlerts:
@KorNov 03.2005 — Hi

by the way...

if(i<3){createAA(oTd,'display','none','style')}

i got 17 cols in total ...what do i do when i dont want display col 9 ,12 ,16

and 17 to

I have just shorten the above code a bit

Thanks Kor[/QUOTE]


modify the condition

if(i==9||i==12||i==16||i==17)
×

Success!

Help @me2 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 5.19,
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,
)...