/    Sign up×
Community /Pin to ProfileBookmark

javascript create list I.E problem, please helpppppppppp!!!!!!!!!!

hello all,
i created a script that creates a list of tables…it is working in firefox and chrome but in i.e doesnt works can anyone tell me why the script is the above…

[code=php]
<script type=”text/javascript”>
window.onload = createform_friend();
//function to create the form
function createform_friend(){
ul_friend = cE(‘ul’, {
id: “ul_friend”
});
}
//function to create the main fields
function addfield_friend(type){
//get the ingredListDiv element and theValue_friend
var parent = document.getElementById(‘friendListDiv’);
var numEle = document.getElementById(‘theValue_friend’);
var num = numEle.value = parseInt(numEle.value, 10)+1;
var tempo=num-1;
//constract a list item
switch(type){
case ‘friend’:
var li = cE(‘li’, {
id: “friend_”+num,
class: “friend-sendlist”
});
break;
}
//constract spanTag
spanTag = document.createElement(“span”);
//constract table

var table = cE(‘table’, {
border : 1,
width : 620
});
//constract two rows in the table
var firstrow = table.insertRow(0);
//CREATE FIRST ROW

//create FirstRow_cell_1
var cell_1 = firstrow.insertCell(0);
cell_1.appendChild(document.createTextNode(‘&#908;&#957;&#959;&#956;&#945; &#945;&#960;&#959;&#963;&#964;&#959;&#955;&#941;&#945;:’));
cell_1.setAttribute(“style”,”padding:2px 0px 4px 6px;”);
cell_1.width = 200;

var div = document.createElement(‘div’);
div.setAttribute(“class”,”friend-text”);
var span = document.createElement(‘span’);
span.appendChild(
cE(‘input’, {
id: “fname”+num,
type: “text”,
name: “fname”+tempo+””,
}));
div.appendChild(span);
cell_1.appendChild(div);

cell_1.appendChild(
cE(‘input’, {
type: “hidden”,
name: “Type[“+tempo+”]”,
value: “text”,
}));

//appending all list objects
spanTag.appendChild(table);
li.appendChild(spanTag);
ul_friend.appendChild(li);
parent.appendChild(ul_friend);
}

//function to create element and assigning attributes
function cE(ele, attributes){
var el = document.createElement(arguments[0]);
if(attributes){
for( var x in attributes ){
el.setAttribute(x, attributes[x]);
}
}
return el;
}
//function to attach event
function AttachEvent(obj,evt,fnc){
if(obj.addEventListener){
obj.addEventListener(evt,fnc,false);
return true;
}
if(obj.attachEvent)
return obj.attachEvent(“on”+evt, fnc);
obj[‘on’+evt] = fnc;// not a perfect solution, still.
}
</script>
[/code]

and call it from html:

[code=php]
<div id=”friendListDiv”></div>
<div id=”hiddenDiv_friend”></div>
<a class=”redbutton” style=”float:left;margin:20px 0 0 10px;” href=”javascript:addfield_friend(‘friend’)”><span>&#928;&#961;&#959;&#963;&#952;&#942;&#954;&#951;</span></a>
[/code]

please help very important for mee…

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliDec 05.2010 — <i>
</i>&lt;script type="text/javascript"&gt;
window.onload = createform_friend();
[/quote]That calls the function immediately, it doesn't wait for the file to load.
Should be:[code] window.onload = createform_friend;
Are there any console messages?
Copy linkTweet thisAlerts:
@dpsimauthorDec 05.2010 — open error console in i.e show errot in this line:
[code=php]
var tempo=num-1;
//constract a list item
switch(type){
[/code]


somewhere there....

any help??
Copy linkTweet thisAlerts:
@FangDec 05.2010 — The cE function won't work correctly in IE: http://alt-tag.com/blog/archives/2006/02/ie-dom-bugs/

Also setAttribute for class and style will fail, use:[CODE]obj.className = "friend-sendlist";
// and
obj.style = "padding:2px 0px 4px 6px; width:200px;";[/CODE]


Use onclick event on the span not JavaScript in the href
×

Success!

Help @dpsim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...