Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

multiple jquery dialogs on the same page?

Posted on 2013-01-23
2
Medium Priority
?
743 Views
Last Modified: 2013-01-24
Here is my working java script for a single JQuery dialog button:
 $.fx.speeds._default = 800;
    $(function  thedialog() {
        $("#myDialog").dialog({

            autoOpen: false,
            show: 'slide',
            hide: 'explode',
            modal: false,
            width: 300,
            minHeight: 200,
            maxHeight: 500,
            buttons: {
                "Close": function () {
                    $(this).dialog("close");
                }
            }
        });

        $("#opener").click(function (e) {
            e.preventDefault();
            $("#myDialog").dialog("open").effect("highlight", {}, 2000);
            ;
            return false;
        });

        function positionDialog() {
            linkOffset = $("#opener").position();
            linkWidth = $("#opener").width();
            linkHeight = $("#opener").height();
            scrolltop = $(window).scrollTop();
            $("#myDialog").dialog("option", "position", [(linkOffset.left - 200 / 2) + linkWidth / 2, linkOffset.top + linkHeight - scrolltop]);
        }

        positionDialog();

        $(window).resize(function () {
            positionDialog();
        });

        $(window).scroll(function () {
            positionDialog();
        });
    });
</script>

Open in new window


In my HTML I use this:
<div id="myDialog" title="Dialog1">
<p>hello world</p>
  </div>
                <input type="image" name="opener" id="opener"  onmouseover="mouseOver()" onmouseout="mouseOut()" src="images/learnmore.png" onclick="return false;" />

Now I want to make another button (up to 10 more), but using the same ID for a button does not work.  If I change my second Button ID, then my script doesn't work.  If I use class="opener" for a second button, that doesn't work.  

 Any ideas on how to get multiple dialog's working on the same page, using image buttons?
0
Comment
Question by:arthurh88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
Khilu earned 2000 total points
ID: 38813281
This might help you.

Passing individual button to open pop up.
onclick="openPopUp(this); return false;"

<input type="image" name="opener" id="opener"  onmouseover="mouseOver()" onmouseout="mouseOut()" src="images/learnmore.png" onclick="openPopUp(this); return false;" /> 


 var thisButton;
        function openPopUp(button) {
            thisButton = $(openPopUp);
            positionDialog(thisButton);
            //e.preventDefault();
            $("#myDialog").dialog("open").effect("highlight", {}, 2000);
            return false;
        }

        function positionDialog(button) {
            linkOffset = button.position();
            linkWidth = button.width();
            linkHeight = button.height();
            scrolltop = $(window).scrollTop();
            $("#myDialog").dialog("option", "position", [(linkOffset.left - 200 / 2) + linkWidth / 2, linkOffset.top + linkHeight - scrolltop]);
        }

        positionDialog(thisButton);

        $(window).resize(function() {
            positionDialog(thisButton);
        });

        $(window).scroll(function() {
            positionDialog(thisButton);
        });

Open in new window

0
 

Author Closing Comment

by:arthurh88
ID: 38813383
thanks!  i managed to get that to work
0

Featured Post

Vim Reference Guide

Vim is a powerful text editor favored by many sysadmins and developers - here are some commands that you'll want to keep in your back pocket!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question