Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Function to create table with specified ASCII symbols

Here is the function, that create table with ASCII symbols from specified ASCII code interval. You can modify it's size and use different styles, onclick function etc. It takes 3 parameters, ID of div element where to attach table, start of ASCII code and end of ASCII code.

<div id='chartable'>
</div>
<script type='text/javascript'>
function draw_chartable(id, start, end)
{
    var div = document.getElementById(id);
    var table = document.createElement('table');
    table.style.border = "1px solid black";
    var new_row = true;
    while(new_row)
    {
        if(start >= end)
        {
            new_row = false;
        }
        var tr = document.createElement('tr');
        for(i = 0; i < 12; i++)
        {
            var td = document.createElement('td');
            if(start < end)
            {
                //define whats inside
                if(String.fromCharCode(start) == " ")
                {
                    td.innerHTML = "&nbsp;";
                }
                else
                {
                    td.innerHTML = String.fromCharCode(start);
                }
                //define id
                td.id = start;
                //define styles
                td.style.cursor = 'pointer';
                td.style.fontWeight = 'bold';
                
                //define onclick function
                //td.onclick = function(){};
                
                start++;
            }
            else
            {
                new_row = false;
                td.innerHTML = "&nbsp;";
            }
            //other style also to apply to empty cells
            td.style.border = "1px solid black";
            td.style.width = '30px';
            td.style.height = '30px';
            td.style.textAlign = 'center';
            td.style.verticalAlign = 'middle';
            tr.appendChild (td);
        }
        table.appendChild(tr);
    }
    div.appendChild(table);
}
draw_chartable("chartable", 32, 127);
</script>

And here's an example:


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus