Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7571857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:46:27+00:00 2026-05-30T15:46:27+00:00

I using PHP/Javascript – Widget of alexmarandon from link http://alexmarandon.com/articles/web_widget_jquery/ And in project of

  • 0

I using PHP/Javascript – Widget of alexmarandon from link http://alexmarandon.com/articles/web_widget_jquery/
And in project of me is:

script.js
html.php
demo.html

In script i using code:

(function() {

// Localize jQuery variable
var jQuery;

/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.7.1') {
    var script_tag = document.createElement('script');
    script_tag.setAttribute("type","text/javascript");
    script_tag.setAttribute("src",
        "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
    if (script_tag.readyState) {
      script_tag.onreadystatechange = function () { // For old versions of IE
          if (this.readyState == 'complete' || this.readyState == 'loaded') {
              scriptLoadHandler();
          }
      };
    } else {
      script_tag.onload = scriptLoadHandler;
    }
    // Try to find the head, otherwise default to the documentElement
    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
    // The jQuery version on the window is the one we want to use
    jQuery = window.jQuery;
    main();
}

/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
    // Restore $ and window.jQuery to their previous values and store the
    // new jQuery in our local jQuery variable
    jQuery = window.jQuery.noConflict(true);
    // Call our main function
    main(); 
}

/******** Our main function ********/
function main() { 
    jQuery(document).ready(function($) { 
        /******* Load CSS *******/
        var css_link = $("<link>", { 
            rel: "stylesheet", 
            type: "text/css", 
            href: "style.css" 
        });
        css_link.appendTo('head');          

        /******* Load HTML *******/
        var jsonp_url = "data.php?callback=?";
        $.getJSON(jsonp_url, function(data) {
          $('#example-widget-container').html(data);
        });
        $('.submit').click(function(){
           alert('test'); 
        });
    });
}

})(); // We call our anonymous function immediately

Then i call data in data.php

$str  = '<div class="widget_advance">';
$str .= '<form method="post" id="form_widget_advance">';
$str .= '<input type="submit" value="Tìm" class="submit" />';
$str .= '</form>';
$str .= '</div>';

echo $_GET['callback'] . '(' . json_encode($str) . ');';

finally, in demo.html is result:

<script src="script.js" type="text/javascript"></script>
<div id="example-widget-container"></div>

=> When I click on button submit is result not show alert('test'); How to fit it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:46:29+00:00Added an answer on May 30, 2026 at 3:46 pm

    Put this inside as such:

    $.getJSON(jsonp_url, function(data) {
      $('#example-widget-container').html(data);
      $('.submit').click(function(){ 
        alert('test'); 
      });
    });
    

    You see, it has to be inside the callback. You can’t bind to the submit button if it’s not in the DOM yet. You could also do something along the lines of: $("#someForm").submit(function() { ... });

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using php or javascript or ajax how to replace specific link to * http://www.google.com/
I did a small web application for using PHP, HTML, and JavaScript. I want
I'm using php,html,javascript,mysql. My functionality goes like this. I have a division made in
I need to do a HTML string concat (using PHP or Javascript) and I
I am making a small file browsing script using PHP and Javascript and I
I have been using PHP and JavaScript for building my dad's website. He wants
I have been programming using PHP, Javascript and have been a designer for a
I'm currently using PHP, JAVASCRIPT, MYSQL, XHTML, CSS to develop my site. Note that
I want to trigger javascript alert using PHP. Is it possible I want to
I've been using PHP for too long, but I'm new to JavaScript integration in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.