Generated Javascript fails

I am in the process of writing a simple Adobe Air application using HTML, jQuery and some jQuery plugin to load RSS feeds.

The problem I am facing is that I am creating a section of HTML components (buttons) so that I can execute specific code when the button is clicked. But when the page is displayed, the button is never executed; I have tried using the built-in log function as well as the warning, but none of them get executed. The weird part is when I copy the HTML component to the part of the page that is not generated, it runs fine.

I insert the following into a div using jQuery and it fails.

'<input type="button" onclick="LoadPage()" value="Test" />' 

      

If I just paste it into HTML it works fine.
I am using version 1.3.2 of jQuery; I am also using this plugin to load data into a div and I have changed line 82 to include the html component above.

I should note that when I inspect the page with the AIR introspector, the HTML is valid.

What could be wrong?

0


a source to share


3 answers


I don't see the problem. The following works great for me:



$(document).ready(function() {
  $('#mainDiv').html('<input type="button" onclick="LoadPage()" value="Test" />');
});

function LoadPage()
{
  alert("Hello");
}

      

+2


a source


If you want to use jquery to handle the click, you can use the live event .

I also had this problem a while ago and it solved the problem.



If you specify your button, the id will look something like this:

$("#YourButtonId").live("click", function (){....

      

0


a source


Do you have the same problem with 'onClick' instead of 'onclick'? Also check to see if "Loadpage" is called instead of "LoadPage".

I sometimes have problems registering in javascript, not sure if these are case sensitive functions.

0


a source







All Articles