Last 5 comments
31 years ago
Rafael:  Thank you very much, I was having a huge headache to solve the very same problem!
37 years ago
Ray:  Having the same problem. Very frustrating. Luckily, for some reason my released version worked on the iPad itself, but now I can't get it to run in the simulator. Getting no such table, which I'm guessing is an initialization error. Will continue to investigate.
38 years ago
Jeremy:  FYI, I've just tried it with the SQLite 3.7.0 preview and the same problem occurs.
Also, I'm not using any extra third-party libraries with my SQLite, so the problem isn't your Unicode extension.
38 years ago
Jeremy:  I'm having the same problem with compiling SQLite against iOS 4 for the iPad simulator, but in my case it works fine running on an actual iPad (also works in the iPhone simulator and on an iPod Touch).
Same problem with 3.6.23.1, 3.6.23, and at least back to 3.6.21. Compiling against iOS 3.2 makes it work, though that's not really an option for iPhone (as opposed to iPad) apps.
I have no idea what to do about it or how big a problem it really is...
38 years ago
Pascal:  The problem seems to have deep roots, however there is a solution, see the updated post. :)
The archive
March 2011  (1)
July 2010  (1)
July 2009  (1)
March 2009  (1)
July 2008  (3)
June 2008  (1)
May 2008  (3)
March 2008  (1)
July 2007  (1)
June 2007  (3)
May 2007  (1)
April 2007  (1)
July 2006  (2)
June 2006  (6)

Dynamically assigning event handlers in IE

Saturday, January 27th 2007 - 00:15
Today I finished some changes to this blog-software – most important is the possibility to get an email whenever someone comments an article you are watching. There is nothing too fancy going on, but I had some problems with the Internet Explorer and dynamically assigned event handlers.
Since the form to submit a comment is fetched via XML and Javascript (AJAX), I have to create all the elements of the form using various DOM methods. Most stuff can simply be assigned using the following method:
var obj = document.createElement('div'); obj.setAttribute("id", "my_id");

There is one well-known caveat to this if you want your code to be compatible with the Internet Explorer; if you want to assign a CSS-class, you must do that using 'className' instead of 'class' only: obj.setAttribute("className", "my_class");. Simply do a browsercheck and then use 'className' or 'class' accordingly.
However, I stumbled upon a more difficult problem: Assinging event handlers (like onsubmit, onmousedown or onfocus) to DOM created objects. To check if a browser supports my AJAX-methods, I use code which executes JavaScript on specific events like <form onsubmit="if(formSubmitted(this)){return false;}">. The Gecko-Engine and Safari let you assign that event-handler like mentioned above, simply using obj.setAttribute(), but this won't work in Internet Explorer 6; I haven't testet IE7 yet.
What I have done is putting the 'string' which contains our code inside an eval() statement and built this eval() statement into an anonymous function. Maybe there is a simpler solution, here is a code block which (in fat) demonstrates how I did it.
// event handlers var is_IE = (navigator.appName.indexOf("Explorer") > -1); var poss = new Array('id', 'type', 'name', 'value', 'class', 'style', 'href', 'method', 'action', 'for', 'src', 'title', 'alt', 'size', 'checked', 'disabled'); var handler_poss = new Array('onsubmit', 'onclick', 'onfocus', 'onblur', 'onmousedown', 'onmouseup'); var xhtml = document.createElement(xml_tree.nodeName);
var attr_value = new Array(); for(var i = 0; i < xml_tree.attributes.length; i++) { var attr = xml_tree.attributes[ i].name; // 'normal' attributes if(in_array(attr, poss) >= 0) { xhtml.setAttribute(((is_IE && ('class' == attr)) ? 'className' : attr), xml_tree.getAttribute(attr)); } // event handlers else if(in_array(attr, handler_poss) >= 0) { if(is_IE) { attr_value[attr] = xml_tree.getAttribute(attr) ? xml_tree.getAttribute(attr).replace(/return /ig, "ret_val = ") : null; try { if('onsubmit' == attr) xhtml.onsubmit = function() { var ret_val = true; eval(attr_value['onsubmit']); return ret_val; }; else if('onclick' == attr) xhtml.onclick = function() { var ret_val = true; eval(attr_value['onclick']); return ret_val; }; else if('onfocus' == attr) xhtml.onfocus = function() { var ret_val = true; eval(attr_value['onfocus']); return ret_val; }; else if('onblur' == attr) xhtml.onblur = function() { var ret_val = true; eval(attr_value['onblur']); return ret_val; }; else if('onmousedown' == attr) xhtml.onmousedown = function() { var ret_val = true; eval(attr_value['onmousedown']); return ret_val; }; else if('onmouseup' == attr) xhtml.onmouseup = function() { var ret_val = true; eval(attr_value['onmouseup']); return ret_val; }; } catch(exc) { } } else { xhtml.setAttribute(attr, xml_tree.getAttribute(attr)); } } }

Notes:
  • You cannot use a return from inside an eval() statement. That's why I replace all occurrences of 'return' and assign the values to a variable ('ret_val' in this case) and return after the eval statement.
  • I had to use the hard-written names of the events ('onsubmit', 'onclick' and so on) although the variable 'attr' carries the same information. Using 'attr' instead results in much simpler code, but you can not use more than one event handler per element or always the last handler will be executed for every preceding handler.
Bert Zwep at 11.12.2007 11:30

I wanted to copy event handlers from on element to another on three browsers: IE7, FireFox2.0 and Opera 9
I wrote therefor the following two fuctions (by the way: they work)
function copyEventHandlers(source,target){ var l,i,atts if(!source||!target)return atts=source.attributes l=atts.length for(i=0
Comments are disabled