Question

My page url is

http://somain.com/test.php?id=1&mview=5

After login the above url shows choice names and images. We have to click add new entry button to add choice images and for remove just we have to click remove button. But the remove button and the file upload section is working fine in chrome and not working in IE 8.

I used a javascript function for adding images for choices. But all the js functions working fine in chrome but it is not working in IE 8. This is the simple coding for removing the file upload section

function addnewchoice(val)
{
var remove = document.createElement("input");
remove.setAttribute("type", "button");
remove.setAttribute("value", "Remove");
remove.setAttribute("onclick", "Remover("+ val +")");
remove.setAttribute("class", "removechoice");
remove.setAttribute("name", removename);
}

function Remover(idval)
{
document.forms['choiceadd']['imageshow'+idval].style.display="none";
document.forms['choiceadd']['choicefile'+idval].style.display="none";
document.getElementById('fileuploadover'+idval).style.display="none";
document.forms['choiceadd']['choicename'+idval].style.display="none";
document.forms['choiceadd']['choicename'+idval].value="";
document.forms['choiceadd']['remove'+idval].style.display="none";
document.getElementById('br'+idval).style.display="none";
}

Anyone please help me to solve this problem. Thank you so much for reading and help me to resolve this problem

Was it helpful?

Solution

According to the first answer here -- IE not allowing onClick event on dynamically created DOM 'a' element -- IE8 does not bind click event handlers automatically when the onclick attribute of an element is changed dynamically. That is, you're setting the onclick attribute of your tag in HTML, but the browser isn't converting that attribute into an actual event handler.

Try replacing

remove.setAttribute("onclick", "Remover("+ val +")");

with

var removeFunc = function() { Remover(val) };
if (!remove.addEventListener) //Old IE
  remove.attachEvent("onclick", removeFunc);
else //Other browsers
  remove.addEventListener("click", removeFunc );

That actually binds the click event handler directly, rather than setting the attribute in the expectation that the browser will react by binding it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top