I have a JavaScript snippet that runs very well on Firefox and Safari, but refuses to run on IE:
var drop= function(id) { if(document.getElementById('select1').value == 'Ficha de pediatria'){ top.location.href = 'print.jsp?id='+id+'&type=2'; } else if(document.getElementById('select1').value == 'Ficha normal'){ top.location.href = 'print.jsp?id='+id+'&type=1'; } } <select id='select1' name='select1' onChange='drop(id);return false;'> <option>Imprimir:</option> <option>Ficha de pediatria</option> <option>Ficha normal</option> </select>
I trimed this as it had more JSP code but it’ remained the same. Anyone got any idea why it’s not running on IE?
[EDIT] Sorry. I introduced an error with my first post by not carefully looking at how you are constructing your url. I shouldn’t have removed the
idparameter. I’ve updated the code and it should work now.Try this instead:
[EDIT] A bit of explanation…
I think the issue is how it is accessing the DOM. I don’t think that IE has a value property on a select. I think you have to get at it via the selected option. Also, I’m not sure that there is a top property in the global namespace, but you should be able to get at it via
window.topto set the location. Finally, I made a slight improvement in that by specifyingthisas the argument, you can skip the element lookup and reference it directly from the control passed as the argument.