简体   繁体   中英

Change style display for cells with Javascript

I want to do something like this: user selects one radio button (lock,delete or compare). I want to show to him only the relevant column from the table. (each option has different column). The table is ajax. I guess i need to change the display style for every cell but i don't know how.

Here is example:

Here i want to change the display of the cells

function ButtonForTbl(value) {
 var x=document.getElementById("audithead").rows[0].cells;
 if (value == "lock"){
 document.getElementById('lock').checked = true;
 //something like for(...)lockCell.style.display=''
 //something like for(...)deleteCell.style.display='none'
 //something like for(...)compareCell.style.display='none'
 }
 else if(value == "delete"){
 document.getElementById('delete').checked = true;
 //something like for(...)lockCell.style.display='none'
 //something like for(...)deleteCell.style.display=''
 //something like for(...)compareCell.style.display='none'
 }
 else{
 document.getElementById('compare').checked = true;
 }
}

I guess i need something like that:

for (i = 0; i < deleteCell.length; i++)
deleteCell[i].style.display='' = true ;

The table:

oCell = oRow.insertCell(-1);
oCell.setAttribute('id','comCell' );
oCell.setAttribute('align', 'center');
oCell.innerHTML = "<input type='checkbox' id='com' value='"+ ind +   "'name='com[]'>";

oCell = oRow.insertCell(-1);
oCell.setAttribute('id','lockCell' );
oCell.setAttribute('align', 'center');
oCell.innerHTML = "<input type='checkbox' id='lock' value='"+ ind +   "'name='lock[]'>";

Radio buttons:

<input type="radio" value="compare" id="compare" name="choose" onclick="ButtonForTbl(this.value)"/> Compare&nbsp;
<input type="radio" value="delete" id="delete" name="choose" onclick="ButtonForTbl(this.value)"/> Delete&nbsp;
<input type="radio" value="lock" id="lock" name="choose" onclick="ButtonForTbl(this.value)"/> Lock<br/>

The table html:

 <table class="auditable">
   <thead id="audithead">
     <tr><td></td></tr>
   </thead>

 <tbody id="auditTblBody">
 </tbody>
 </table>

EDIT: Full row is like that:

<tr>
<td align="center" id="lockCell" style="display: none;">
<input type="checkbox" onclick="" name="lock[]" value="1500" id="lock"></td>
<td align="center" id="delCell" style="display: none;">
<input type="checkbox" name="del[]" value="1500"></td>
<td align="center" id="comCell">
<input type="checkbox" onclick="setChecks(this)" name="com[]" value="1500" id="com"></td>
<td width="65px">100%    1/1</td><td width="105px">2011-01-10 17:47:37</td>
</tr>

Thank you so much!

You can do the same thing with a div or any other element. The javascript would look like:

<script language='javascript'>
<!-- //
function setProperties(obj)
{
if(obj.value == "yes")
{
document.mydiv.style.display = "block";
} else {
document.mydiv.style.display = "none";
}
}
// -->
</script>

And in the body:

<input type=radio name="update" value="yes" checked onclick="setProperties(this)">Yes<br />
<input type=radio name="update" value="no" onclick="setProperties(this)">No<br />
<div id='mydiv'>some text here</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM