Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Passing a value to a dialog

Posted on 2011-10-25
Medium Priority
Last Modified: 2012-05-12
Hello all,

I'm on a bit of a charge today with my questions! Still getting to grips with the way jquery flows :)

I have a set of dynamically output buttons with varying values assigned. What I want to do is pass this to a dialog when that is called.

I use php to write the value in the onClick function like so:

<span class="favorite" onclick="addFavorite('.$doc_id.')">Add to Favorites</span>

Open in new window

And I have the dialog setup:

		var $addfavorite = $('#addfavorite')
				autoOpen: false,
				title: 'Add to Favorites',
				draggable: false,
				modal: true,
				resizable: false,
				width: 420,
				height: 250,
				position: ['center',100],
				close: function(event, ui) {


Open in new window

With placeholder div just under body:

<div id="addfavorite"></div>

Open in new window

Now the function:

$.addFavorite = function(doc_id)



Open in new window

Is leaving me blank in my head - how do I get the value (doc_id) into the addfavorite.php page that is loaded into the dialog?
Question by:dolythgoe
  • 4
  • 2
LVL 28

Expert Comment

ID: 37024694
<div id="addfavorite"><span id="MyDocID"></span></div>

$.addFavorite = function(doc_id)

$('.MyDocID").innerHTML = doc_id;


Author Comment

ID: 37024724
Thanks for that but I can't really use <div id="addfavorite"> because there's a load of them.

Consider a whole page of search results on documents with 'add to favorite' button by each one. What I'm trying to do is when they click the 'add to favorite' button, a dialog popsup to ask for some more detailes - like which folder they want to save it in. For this to happen I need the docId sent via a get/post to the php file.

hmmmm...maybe I should do the ajax request and get the php file to open the dialog?
LVL 28

Accepted Solution

strickdd earned 2000 total points
ID: 37024850
You can add the docid to a hidden field and that will post when the page posts, or you can pull it from the hidden field into an AJAX post.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 37025841
I can get the var into an ajax request but it's getting the window to popup with the content that confuses me.

The php page contained within the dialog needs to know the variable so I need to essentially pass docID to some function that loads the php page into the dialog.

So let's work this through:

- User clicks 'Add Favorite' with docid 7 for example
- Up pops dialog and loads addfavorite.php?docid=7
- From there some actions can be performed and saved to db

Saying that, I guess my question is now I do I load a page into the dialog without having to specify it first when creating the dialog in the document load function?

Assisted Solution

dolythgoe earned 0 total points
ID: 37043832
Achieved this in the end by doing this:

		$.addFavorite = function(doc_id, doc_title)

			$('#addfavorite').load('addfavorite.php?doc_id=' + doc_id + '&doc_title=' + link_title);


Open in new window


Author Closing Comment

ID: 37068281
Thanks for you help - used a mixture of both solutions

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

571 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