PDA

View Full Version : Wanted someone to debug this script, it doesn't work with IE.



mechakoopa
10-25-2005, 10:35 AM
This is that webpage.
http://yoshibestiary.servegame.org/bnpb/posting.php?mode=newtopic&f=1

I've making phpBB MOD that user will can add poll without reload the page many times.

After clicked the button [ Add Option ] on Internet Explorer, it returns "Unknown Error" or Error #0

            // A function to add poll option.
            function addoptions() {
                pollids++;
                currentobj = document.getElementById('postingT').insertRow(document.getElementById('newPollRow').rowIndex);
                // OKay, this is the HTML of the newly added poll row!
&#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; tmphtml = '<td class="row1"><span class="gen"><b>{L_POLL_OPTION}</b></span></td>'
&#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; tmphtml += '<td class="row2"><span class="genmed"><input type="text" name="poll_option_text[' + pollids + ']" size="50" class="post" maxlength="255" value="" /></span>'
&#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; tmphtml += '<input type="button" onClick="document.getElementById(\'postingT\').deleteRow(document.getElementById(\'tehpolid' + pollids + '\').rowIndex); pollids--; return false;" value="{L_DELETE_OPTION}" class="liteoption" />'
&#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; tmphtml += '</td>';
&#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; currentobj.innerHTML = tmphtml;
&#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; // Since currentobj.id is read-only!
&#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; &#0160; currentobj.setAttribute('id','tehpolid' + pollids);
&#0160; &#0160; &#0160; &#0160; &#0160; &#0160; }
There's an error in that red line.
Can anyone help me fixing this problem please?
Thank you,
DTTVB

mwinter
10-26-2005, 07:10 PM
currentobj = document.getElementById('postingT').insertRow(document.getElementById('newPollRow').rowIndex);
/* ... */
currentobj.innerHTML = tmphtml;
The innerHTML property is read-only in IE for most table-related elements, including col, colgroup, table, tbody, tfoot, thead, and tr[1]. It's also read-only for some other elements, too: frameset, html, style, and title.

Use DOM methods, like insertCell, instead.



// Since currentobj.id is read-only!
The id property is only read-only in IE4...



currentobj.setAttribute('id', 'tehpolid' + pollids);
...and using the setAttribute method isn't any different - it's just ignored. Moreover, this method exhibits broken behaviour in IE and is best avoided, anyway.

Mike

mechakoopa
10-28-2005, 10:32 AM
OK! So the code now would be this

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; tmphtml_r1 = '<span class="gen"><b>{L_POLL_OPTION}</b></span>';
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; tmphtml_r2 = '<span class="genmed"><input type="text" name="poll_option_text[' + pollids + ']" size="50" class="post" maxlength="255" value="" /></span> ';
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; tmphtml_r2 += '<input type="button" onClick="document.getElementById(\'postingT\').deleteRow(document.getElementById(\'tehpolid' + pollids + '\').rowIndex); pollids--; return false;" value="{L_DELETE_OPTION}" class="liteoption" />';

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; row2 = currentobj.insertCell(0);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; row2.className = 'row2';
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; row2.innerHTML = tmphtml_r2;

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; row1 = currentobj.insertCell(0);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; row1.className = 'row1';
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; row1.innerHTML = tmphtml_r1;

I made a new <td> element, and change its class name, and insert HTML code, that's worked, and just know that TR is read-only, thanks!