/    Sign up×
Community /Pin to ProfileBookmark

Help! Javascript not working in IE

I really appreciate your helps!

Today I wrote a code with javascript to create a new table row when I press a “Add” button. It works very well in the Mozilla. But when I tried in the IE, it dosen’t work. When I pressed the button, no new row is created and also no error in the page. The codes are as follows:

<html>
<head>

<script language=”JavaScript”>

function addService()
{
var a = navigator.userAgent.indexOf(“MSIE”);
var style_display;

if ( a!=-1) {
style_display=’block’; }
else {
style_display=’table-row’; }

mycurrent_table = document.getElementById(“outbound_table”);
mycurrent_row=document.createElement(“div”);
mycurrent_col=document.createElement(“td”);
mycurrent_col.setAttribute(“align”,”center”);
mycurrent_col.style.display=style_display;

_m1 = ‘<input type=”text” value=”test1″>’;
mycurrent_col.innerHTML = _
m1;
mycurrent_row.appendChild(mycurrent_col);
mycurrent_table.appendChild(mycurrent_row);
}
</script>

</head>
<body >

<form name=”Outbound Service”
method=”post”>

<table bgbolor=”White” width=”100%” id=”outbound_table”>

<tr>
<td bgcolor=”#0033CC” align=”center” colspan=”6″>

<font face=”Verdana,Arial” size=”2″ color=”#FFFFF”><b>Outbound
Services</b></font>
</td>
</tr>

<tr bgcolor=”#FFFFD6″ id=”service_header”>
<th></th>
</tr>

<tr bgcolor=”#CCCCCC” id=”serviceList”>
<td align=”center” id=”service_radio”>
<input type=”text” >
</td>
</tr>
</table>

<tr id=”service_button”>
<table width=”100%”>
<tr>
<td align=”right”>
<input type=”Button” value=”Add” class=”button1″
onclick=”addService()”>
</td>

<td align=”center”>
<input type=”Button” value=”Save” class=”button1″>
</td>
<td align=”left”>
<input type=”Button” value=”Delete” class=”button1″

onclick=”deleteService()”>
</td>
</tr>
</table>

</tr>

</form>
</body>
</html>

Thanks,

Rui ?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdOct 06.2005 — IE doesn't support "table-row" CSS2 specification
Copy linkTweet thisAlerts:
@reinmontrealauthorOct 06.2005 — yes, the "style_display" equals to "block" when I use the IE. I have tried to just set the display as 'block', also it doesn't work.
Copy linkTweet thisAlerts:
@WebnerdOct 06.2005 — Ie appends a TBODY tag inside the table tag so your parent element is no longer the TABLE. Add this for IE:

var tbody=mycurrent_table.getElementsByTagName("tbody");

var mycurrent_table=tbody.item(0);
Copy linkTweet thisAlerts:
@reinmontrealauthorOct 06.2005 — Hi Webnerd,

The problem has been solved according to your suggestions. Thank you so much!

Rui
Copy linkTweet thisAlerts:
@reinmontrealauthorOct 06.2005 — Hi Webnerd,

I have another problem. In IE, I want to change the background color of the new table row, but it doesn't work.

mycurrent_table = document.getElementById("outbound_table");

var tbody = mycurrent_table.getElementsByTagName("tbody");

var mytable = tbody.item(0);

mycurrent_row=document.createElement("tr");

mycurrent_row.setAttribute("bgcolor", "#FFFFD6");

Do you know why? Thank you very much!

Rui
Copy linkTweet thisAlerts:
@WebnerdOct 07.2005 — Try using a style,

mycurrent_row.style.backgroundColor="#FFFFD6";

If it doesn't work, then you probably have a persisting style for the table as whole that has priority over the TR. Remove the <table bgcolor=""> and see if that changes anything.
Copy linkTweet thisAlerts:
@reinmontrealauthorOct 07.2005 — Thanks, Webnerd. I changed to " mycurrent_row.style.backgroundColor="#FFFFD6";", and it works.

Thank you so much!

Rui
Copy linkTweet thisAlerts:
@felgallOct 07.2005 — Don't use [b]var a = navigator.userAgent.indexOf("MSIE");[/b] to test for IE. A lot of other browsers will set that value in order to masquerade as IE in order that scripts incorrectly written to test for IE will run on those other browsers as well.
×

Success!

Help @reinmontreal 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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