[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

JQuery Dialog, Passing a variable from link to javascript

Asked by beigs in Jquery, JavaScript, Asynchronous Javascript and XML (AJAX)

Tags: jquery, javascript, php, dialog, modal

I an running jQuery on a application and am struggling a little bit with passing a variable from the link that opens a modal-dialog into javascript.  Example, I have a page that lists user accounts.  Next to each user account, I have a "delete" icon.  When the user clicks the icon, I have a modal box that opens for confirmation.  Once the user confirms the delete, I'm using AJAX/POST to send the information to a php file.

The first problem I ran into was getting the jQuery script to run the same modal box multiple times because the '<a id=' was always the same.  I fixed this by changing the id in the array to 'delete-user-$USERNAME' and then using $("a[id^='delete-user']").click(function() to open the dialog no matter which icon was clicked.  

The problem I am running into now is extracting that username in javascript to pass it to the ".ajax/data: " variable.

Please note that I added the 'if (deleteUser != "")' for debugging purposes.

I know this should be simple, but my brain is fried from looking at it so long and I just can't see the solution.  Any help would be appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
<a href="#" id="delete-user-<?php echo $uary['username']; ?>" title="Delete User" style="display: inline-block; width: 16px; height: 16px;" class="ui-state-default ui-corner-all ui-widget ui-helper-clearfix ui-icon ui-icon-trash"></a>	
 
then in jquery...
 
jQuery(document).ready( function(){ 
		
		var fullID = $("a").attr("id"),
			deleteUser=fullID.replace(/delete-user-/,"");
		
		$("#remove_user").dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			buttons: {
				'Delete Account': function() {
					
					if (deleteUser != "") {
						$.ajax({
							type: "POST",
							url: "func/remove_user.php",
							data: "username=" + deleteUser
						});
						$(this).dialog('close');
						window.location = "userManagement.php";
					} else {
						alert("No Data Detected");
					}
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
		});
		
		$("a[id^='delete-user']").click(function() {
			$('#remove_user').dialog('open');
		})
 
	});
[+][-]08/13/09 06:56 AM, ID: 25088227Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Jquery, JavaScript, Asynchronous Javascript and XML (AJAX)
Tags: jquery, javascript, php, dialog, modal
Sign Up Now!
Solution Provided By: beigs
Participating Experts: 1
Solution Grade: A
 
[+][-]08/13/09 05:44 AM, ID: 25087514Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625