/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Firefox problem with removeChild()

Hello all,

I had a look on this forum but didn’t find any solution to my problem. I have this js code:

[CODE]<script type=”text/javascript”>
function addElement() {
var ni = document.getElementById(‘myDiv’);
var numi = document.getElementById(‘theValue’);
var num = (document.getElementById(‘theValue’).value -1)+ 2;
numi.value = num;
var newdiv = document.createElement(‘div’);
var divIdName = ‘my’+num+’Div’;
newdiv.setAttribute(‘id’,divIdName);
if(num > 8) document.myDiv.innerHTML = ‘Answers can’t be more than 8.’;
else newdiv.innerHTML = ‘Answer ‘+num+’: <input type=”text” name=”f_answer’+num+'” size=”40″ maxlength=”50″> <a href=”#” onclick=”removeElement(‘+divIdName+’)”>remove option</a>’;
ni.appendChild(newdiv);
}

function removeElement(divNum) {
var d = document.getElementById(“myDiv”).removeChild(d);
//d.removeChild(divNum);
}
</script>[/CODE]

and this is my form

[CODE]<form name=”f_poll” action=”poll_make.php” method=”post”>

<div>Answer 1: <input name=”f_answer1″ size=”40″ maxlength=”50″ value=”The best” type=”text”></div>
<div>Answer 2: <input name=”f_answer2″ size=”40″ maxlength=”50″ value=”Good” type=”text”></div>
<div>Answer 3: <input name=”f_answer3″ size=”40″ maxlength=”50″ value=”Not enough” type=”text”></div>
<div>Answer 4: <input name=”f_answer4″ size=”40″ maxlength=”50″ value=”Not at all” type=”text”></div>
<div id=”myDiv”>
<div id=”my5Div”>Answer 5: <input name=”f_answer5″ size=”40″ maxlength=”50″ type=”text”> <a href=”#” onclick=”removeElement(my5Div)”>remove option</a></div>
<div id=”my6Div”>Answer 6: <input name=”f_answer6″ size=”40″ maxlength=”50″ type=”text”> <a href=”#” onclick=”removeElement(my6Div)”>remove option</a></div>
<div id=”my7Div”>Answer 7: <input name=”f_answer7″ size=”40″ maxlength=”50″ type=”text”> <a href=”#” onclick=”removeElement(my7Div)”>remove option</a></div>
</div>

</form>[/CODE]

When i press remove option it works fine in IE but not in Firefox. Can sb find any solution to that. I appreciate your time…

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarSep 14.2009 — var d = document.getElementById("myDiv").removeChild([B]d[/B]);
Where do you set [b]d[/b] in the global scope? Is it's value still set? Does it still point to a valid number?
Copy linkTweet thisAlerts:
@billyarmeauthorSep 14.2009 — Last 3 lines of js function are wrong. My bad. This is the correct:

[CODE]
function removeElement(divNum) {
var d = document.getElementById("myDiv");
d.removeChild(divNum);
}
[/CODE]


i can use either this code an works also fine in IE bu tno in Firefox:

[CODE]
function removeElement(divNum) {
document.getElementById("myDiv").removeChild(divNum);
}
[/CODE]
Copy linkTweet thisAlerts:
@Sterling_IsfineSep 14.2009 — You're passing an ID as a variable, which I.E. accepts but nothing else does.

This must be generating an error in the console.

Try passing the ID as a string:

[CODE]<div id="my5Div">Answer 5: <input name="f_answer5" size="40" maxlength="50" type="text"> <a href="#" onclick="removeElement([B][COLOR="Red"]'[/COLOR][/B]my5Div[B][COLOR="Red"]'[/COLOR][/B])">remove option</a></div>
.
.
.
function removeElement(divNum)
{
document.getElementById("myDiv").removeChild( document.getElementById( divNum ) );
}[/CODE]
Copy linkTweet thisAlerts:
@billyarmeauthorSep 14.2009 — Yeap that worked Sterling Isfine!!! Thx a lot!! quotes was the problem!!!
×

Success!

Help @billyarme 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.23,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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