This function executes the first time correctly, but the next time the function returns an error.
function edit_div(id)
{
if(edit_status == 0)
{
document.getElementById("addnew").innerHTML = '<form><h5>Move</h5>Top Margin: <input type="text" id="topmargin"></br>Left Margin: <input type="text" id="leftmargin"></br><h5>Backgorund</h5>Background Color: <input type="text" id="backgroundcolor"></br><h5>Border</h5>Border Width: <input type="text" id="borderwidth"></br>Border Type: <input type="text" id="bordertype"></br>Border Color: <input type="text" id="bordercolor"></br><input type="button" value="Edit Div" onclick="edit_div('+id+');"></form>';
edit_status = 1;
}
else
{
var Top = document.getElementById("topmargin").value;
var Left = document.getElementById("leftmargin").value;
var Background_Color = document.getElementById("backgroundcolor").value;
var Border_Width = document.getElementById("borderwidth").value;
var Border_Type = document.getElementById("bordertype").value;
var Border_Color = document.getElementById("bordercolor").value;
var num = id;
var new_id = "a"+num;
var b_id = "b"+num;
document.getElementById(new_id).style.top = Top;
document.getElementById(new_id).style.left = Left;
document.getElementById(new_id).style.backgroundColor = Background_Color;
document.getElementById(new_id).style.border = Border_Width+" "+Border_Type+" "+Border_Color;
g_code = document.getElementById(b_id).innerHTML; //ERROR HERE ERROR HERE ERROR
css_graphic[id] = g_code;
//-------
document.getElementById(new_id).removeAttribute("onClick");
b_code = document.getElementById(b_id).innerHTML;
css_code[id] = b_code;
edit_status = 0;
document.getElementById("addnew").innerHTML = '';
edit_css()
}
}
As you can see I have the error marked with some comment //error here error here
Error: Uncaught TypeError: Cannot read property 'innerHTML' of null
The code executes perfectly fine the first time through after displaying the form, then submitting the form it works perfectly, but when you display the form again and click submit the code will come up with an error :(:@:sad: