Hey all, I have been wanting to create a on the fly editable data table so I have done so. I have so me little things that I need to do like remove divs that are not needed anymore. This code work in FireFox and IE but the formating is wrong in IE, Can someone take a look at this and let me know what I am doing wrong?
If you click on a box, you can edit the information on the fly. In FF all is good, in IE the boxes shift.
Here is the code
Thanks again.
-T
-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!
If you click on a box, you can edit the information on the fly. In FF all is good, in IE the boxes shift.
Here is the code
Code:
<html>
<head>
<title>Grid v.01</title>
<style type="text/css">
.t1, .t2, .t3, .t4, .c1, .c2, .c3, .c4, .yes, .no {
display: block;
float: left;
width:1000px;
padding:1px;
margin:2px;
}
.t1, .t2, .t3, .t4 {
width: 200px;
background-color:#8FABFF;
font-weight:bold;
}
.t3 {
width: 100px;
}
.t4 {
width: 100px;
}
.c1, .c2, .c3, .c4{
width: 200px;
background-color:#DBF4FF;
}
.c3 {
width: 100px;
}
.c4 {
width: 100px;
}
.yes {
width:100px;
}
.no {
width:30px;
}
br {
clear: left;
}
</style>
<script type="text/javascript" src="../prototype.js"></script>
<script type="text/javascript">
var elemets = {
/*
* This is the top div that will house 2 seperate divs, 1 is visibal and that other is hidden.
*/
newTopElement : function(divID, container)
{
// Creating the top div
var e = document.createElement("DIV");
e.id = divID;
$(container).appendChild(e);
},
newChildElement : function(divID,container,cName,Info)
{
/*
* Creating the first div, this will have the innerHTML populated with data from the database
*/
var e = document.createElement("DIV");
e.id = divID; // This is the div id
e.className = cName;
e.onclick = function() {HideMe(divID)}; // This is the call name
$(container).appendChild(e); // Appending the information to the parent div
$(divID).innerHTML = Info; // This is what will be displayed
/*
* This dive is hidden and will house a textbox when pressed.
*/
var b = document.createElement("DIV");
b.id = divID + 'change';
//b.className = cName;
b.style.display = "none";
$(container).appendChild(b);
},
newBreak : function(container)
{
var e = document.createElement("BR"); // Creating the break element
$(container).appendChild(e);
}
}
function init(what)
{
/*
* I am going to create the datagrid (tabledata) on the fly
* elemets.newChildElement(ne+'M',ne,'c1', what.tools[x].manufacturer);
* ne+M is the name of the new div for that element
* ne is the name if the parent element
* c1 is the name of the class
*/
var x = 0;
while(x < what.tools.length){
var ne = 'r' + x;
elemets.newTopElement(ne,'container');
elemets.newChildElement(ne+'M',ne,'c1', what.tools[x].manufacturer);
elemets.newChildElement(ne+'N',ne,'c2', what.tools[x].name);
elemets.newChildElement(ne+'V',ne,'c3', what.tools[x].version);
elemets.newChildElement(ne+'E',ne,'c4', what.tools[x].experence);
elemets.newBreak(ne);
x++;
}
}
function HideMe(what)
{
var tempHold = $(what).innerHTML;
//$(what).innerHTML = '';
$(what).style.display = 'none';
$(what + 'change').style.display = 'block';
var d = document.createElement('Input');
d.setAttribute("type","text");
d.setAttribute("class", $(what).className);
d.setAttribute("value", $(what).innerHTML);
d.setAttribute("id", what + 'temptext');
d.onblur = function() {updateData(what)};
$(what + 'change').appendChild(d);
}
function updateData(what)
{
// First thing that I have to do is get the parent ID so I can make sure I delete the correct child ID
var a = document.getElementById(what).parentNode ;
// I am now taking what is in the text box and adding it to the innerhtml of the hidden div
$(what).innerHTML = ($F(what + 'temptext'));
// I am now hidding the textbox.
$(what + 'temptext').style.display = 'none';
// I am now unhiding the div
$(what).style.display = 'block'
// Finish working with the data located in
}
var data = { "tools" : [
{"manufacturer":"Microsoft","name":"windows server","version":"15874","experence":"Expert"},
{"manufacturer":"Microsoft","name":"Visio","version":"Pro","experence":"Good"},
{"manufacturer":"Telelogic","name":"Doors","version":"8.55d","experence":"Good"}
]}
</script>
</head>
<body onload="init(data)">
<h1>Click on a box</h1>
<div id="masterHeader">
<div class="t1">Manufacturer </div>
<div class="t2">Name</div>
<div class="t3">Version</div>
<div class="t4">Experience</div>
<br />
</div>
<div id="container">
</div>
</div>
<br/>
<br/>
<br/>
<div id="putHere">Put Here</div>
</body>
</html>
Thanks again.
-T
-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!