0

I am trying to open a chat portal in a dialog using jquery.

Here is my code

<img class="chatBtn" id="chat_btn" style="margin-top: 10px; margin-left: 10px" src="images/colored_livecha.png" alt="" width="80" height="33" />

jQuery('.chatBtn').click(function() {
  var dlg = jQuery('#chat_btn').dialog({
    autoOpen: 'false',
    modal: 'true',
    minHeight:'300px',
    minWidth: '300px'
  });

  dlg.load('chat.php', function(){
    dlg.dialog('open');
  });
});

However on click nothing happens. What amendments are required?

3 Answers 3

2

You'll need to wrap that in a script tag.

 <script>
jQuery('.chatBtn').click(function() 
{

  var dlg = jQuery('#chat_btn').dialog(
    {
 autoOpen: 'false',
  modal: 'true',
  minHeight:'300px',
  minWidth: '300px'
  });

dlg.load('chat.php', function(){
         dlg.dialog('open');
     });
});
 </script>

Another question, is jQuery included in the head or somewhere in the page?

Sign up to request clarification or add additional context in comments.

9 Comments

I have a separate jquery file in which all these functions are within jQuery(document).ready(function() { and yes jquery is added in header
i can't get it work, nothing happens when i click on it. if i put alert('ok') it works
Now the javascript is at least running. Do you get any javascript errors? Have you opened developer tools? F12 in chrome, or in firefox u'll need to install firebug.
Well it gives TypeError : Undefined is not a function.
can you run this in the console of the developer tools: jQuery What does it return? Also, dialog is part of jQuery UI I do believe. Have you included this as well?
|
1

The simplest way would be to get the information in the database using PHP, and populate the UI tables like that. The major downside would be loading time. If you find that the page is taking too long to load, then you may want to look into jQuery's .ajax()

1 Comment

its a chat panel. I want to open it in a dialog box.
0

I think you need to reference jquery library :

  1. href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css.
  2. src="//code.jquery.com/jquery-1.10.2.js".
  3. src="//code.jquery.com/ui/1.10.4/jquery-ui.js".
  4. rel="stylesheet" href="/resources/demos/style.css".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.