PDA

View Full Version : createElement in IE


vikaspawar
04-01-2008, 09:43 AM
i have some problem with javascript my code below is not supporting in IE 7
PLZ TELL ME if there is any solution
attrid, attrName is the function parameteres
if(con==true)
{
alert("Attribute name changed Successfully");

var divChld = document.createElement("tr");
divChld.id='div_'+attrid;
var input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("name", "txt_"+attrid);
input.setAttribute("id", attrid);
input.setAttribute("value", attrName);
var input1 = document.createElement("input");
input1.setAttribute("type", "button");
input1.setAttribute("name", "cmd_"+attrid);
input1.setAttribute("id", attrid);
input1.setAttribute("value", "Update");
input1.setAttribute("onclick",'hide("+attrid+")');
var input2 = document.createElement('input');

input2.setAttribute("type", "button");
input2.setAttribute("name", "cmd_"+attrid);
input2.setAttribute("id", attrid);
input2.setAttribute("value", "cancel");
input2.setAttribute("onclick","hide()");
divChld.appendChild(input);
divChld.appendChild(input1);
divChld.appendChild(input2);
var row=document.getElementById("div1");
row.appendChild(divChld);



} this event fires onclick of some button passing it id and val
i works fine in mozilla firefox 2.0 but didnt work in the IE7
If anyone knows solution plz let me know

Kor
04-01-2008, 12:37 PM
use DOM 0 syntax (IE does not consider events as attributes), a custom property and and a closure

...
input1.setAttribute("value", "Update");
input1.att=attrid;
input1.onclick=function(){hide(this.att)};
...

vikaspawar
04-01-2008, 02:11 PM
thanks for reply it really works

vikaspawar
04-17-2008, 01:16 PM
Thanks

its rally working

roma276
05-28-2009, 07:30 AM
Hi there all, I also have trouble with createElement in IE
var Count = -1;
function add_tpl()
{
Count++;



var new_tpl_min_comm = document.createElement('input');
new_tpl_min_comm.type = 'text';
new_tpl_min_comm.name = 'min_comm['+Count+']';
new_tpl_min_comm.size = '7';

var new_tpl_max_comm = document.createElement('input');
new_tpl_max_comm.type = 'hidden';
new_tpl_max_comm.name = 'max_comm['+Count+']';
new_tpl_max_comm.size = '7';

var new_tpl_value = document.createElement('input');
new_tpl_value.type = 'text';
new_tpl_value.name = 'tpl_value['+Count+']';
new_tpl_value.size = '7';

var new_tpl_type_select = document.createElement('select');
new_tpl_type_select.id = 'tpl_select['+Count+']';
new_tpl_type_select.name = 'tpl_select['+Count+']';

var new_tpl_type_option = document.createElement('option');
new_tpl_type_option.value = '0';
new_tpl_type_option.text = '<? echo iconv("utf-8","windows-1251","я┌п╦п©")?>';


var new_tpl_type_option1 = document.createElement('option');
new_tpl_type_option1.value = '1';
new_tpl_type_option1.text = '%';

var new_tpl_type_option2 = document.createElement('option');
new_tpl_type_option2.value = '2';
new_tpl_type_option2.text = '<? echo iconv("utf-8","windows-1251","я─я┐п╠п╩п╦")?>';


var new_tr = document.createElement('tr');
new_tr.id = 'new_tr['+Count+']';



var new_td2 = document.createElement('td');
new_td2.id = 'new_td2['+Count+']';

var new_td3 = document.createElement('td');
new_td3.id = 'new_td3['+Count+']';

var new_td4 = document.createElement('td');
new_td4.id = 'new_td4['+Count+']';

var new_td5 = document.createElement('td');
new_td5.id = 'new_td5['+Count+']';

var new_br = document.createElement('br');
var new_br1 = document.createElement('br');
var new_br2 = document.createElement('br');
var new_br3 = document.createElement('br');
var new_br4 = document.createElement('br');
var new_br5 = document.createElement('br');




var textNodeMin = document.createTextNode('<? echo iconv("utf-8","windows-1251","п·я┌:")?>');
var textNodeMax = document.createTextNode('<? echo iconv("utf-8","windows-1251","")?>');
var textNodeValue = document.createTextNode('<? echo iconv("utf-8","windows-1251","я─я┐п╠. п*п╬п╪п╦я│я│п╦я▐")?>');
var textNodeRub = document.createTextNode('<? echo iconv("utf-8","windows-1251","")?>');


document.getElementById('fs').appendChild(new_tr);

document.getElementById('new_tr['+Count+']').appendChild(new_td2);
document.getElementById('new_tr['+Count+']').appendChild(new_td3);
document.getElementById('new_tr['+Count+']').appendChild(new_td4);
document.getElementById('new_tr['+Count+']').appendChild(new_td5);

document.getElementById('new_td2['+Count+']').appendChild(textNodeMin);
document.getElementById('new_td2['+Count+']').appendChild(new_tpl_min_comm);
document.getElementById('new_td3['+Count+']').appendChild(textNodeMax);
document.getElementById('new_td3['+Count+']').appendChild(new_tpl_max_comm);
document.getElementById('new_td4['+Count+']').appendChild(textNodeValue);
document.getElementById('new_td4['+Count+']').appendChild(new_tpl_value);
document.getElementById('new_td5['+Count+']').appendChild(new_tpl_type_select);
document.getElementById('tpl_select['+Count+']').appendChild(new_tpl_type_option);
document.getElementById('tpl_select['+Count+']').appendChild(new_tpl_type_option1);
document.getElementById('tpl_select['+Count+']').appendChild(new_tpl_type_option2);

}

any things about my problem?