IE events on the fly

C

Cy

This works wonderfully in Firefox, but when it runs for the first time
in IE it only creates the field, but won't create any attributes for
the events. When debugging the events are null. How can I get this
to work in IE.

The table that looks like this

<table width="100%" border="1" cellpadding="0" cellspacing="2">
<tbody id="linkedTable">
<tr>
<td class="content">1) </td>
<td><input type="text" name="linked_form[]" id="linked_form1"
onKeyUp="cellHilite('linked', 'form'); addInputField('linkedTable',
'linked_form', '1', '90')" onBlur="cellHiliteOff()" size="90"></td>
</tr>
</tbody>
</table>

My script is like this
var fieldNum = 0;
function addInputField(tagID, fieldName, num, length) {
var newNum = 1+parseInt(num);
var funcText = "addInputField('" + tagID + "','" +
fieldName + "','" + newNum + "','" + length + "')"

if (document.getElementById(fieldName+num).value != '') {
row = document.createElement('TR');
cell = document.createElement('TD');
cell.setAttribute("class", 'content');
cell2 = document.createElement('TD');
cell2.setAttribute("class", 'content');
txt = document.createTextNode(newNum + ') ');
field_input = document.createElement('INPUT');
field_input.setAttribute("type", 'text');
field_input.setAttribute("id", fieldName + newNum);
field_input.setAttribute("name", fieldName+"[]");
field_input.setAttribute("size", length);
field_input.setAttribute("onKeyUp",
"cellHilite('linked', 'form'); "+funcText);
field_input.setAttribute("onMouseUp",
"cellHilite('linked', 'form'); "+funcText);
field_input.setAttribute("onBlur", "cellHiliteOff()");

if (fieldNum != num) {
document.getElementById(tagID).appendChild(row);
row.appendChild(cell);
cell.appendChild(txt);
row.appendChild(cell2);
cell2.appendChild(field_input);
}
fieldNum = num;
}
}






I had done this before, but without a table. The inputs were placed
on top of each other in a div tag. That code looks like this.
function addURLField(num) {
if
(document.getElementById('request_form')['url_'+num].value != '') {
url_input = document.createElement('INPUT');
url_input.setAttribute("type", 'text');
url_input.setAttribute("name", 'url[]');
url_input.setAttribute("id", 'url_'+ (1+parseInt(num)));
url_input.setAttribute("size", '127');
url_input.setAttribute("onKeyUp", "addURLField(\'" + (1+parseInt(num))
+ "\')");
url_input.setAttribute("onMouseUp", "addURLField(\'" +
(1+parseInt(num)) + "\')");
bold_tag = document.createElement("B");
numb = document.createTextNode((1+parseInt(num))+")-");
bold_tag.appendChild(numb);

if (probURLnumKeep != num) {
br_tag2 = document.createElement('BR');
document.getElementById('new_page_toggle').appendChild(bold_tag);
document.getElementById('new_page_toggle').appendChild(url_input);
document.getElementById('new_page_toggle').appendChild(br_tag2);
}
probURLnumKeep = num;
}

}

Any help would be appreciated
 
W

web.dev

Cy said:
field_input.setAttribute("type", 'text');
field_input.setAttribute("id", fieldName + newNum);
field_input.setAttribute("name", fieldName+"[]");
field_input.setAttribute("size", length);

The setAttribute function does not work correctly in IE. Do this
instead:

field_input.type = "text";
field_input.id = fieldName + newNum;
field_input.name = fieldName + "[]";
field_input.size = length;
field_input.setAttribute("onKeyUp",
"cellHilite('linked', 'form'); "+funcText);
field_input.setAttribute("onMouseUp",
"cellHilite('linked', 'form'); "+funcText);
field_input.setAttribute("onBlur", "cellHiliteOff()");

Events are a different matter. You should be using addEventListener
and attachEvent (IE) methods. Please look them up on how to use them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top