Solved

loop over links to create dialog boxes on divs using .each

Posted on 2011-09-23
6
311 Views
Last Modified: 2012-06-27
I have a table of dynamic rows with links built in - that are named based on the id of the current record.  (see code)

Then I have a set of hidden divs that are created in the same manner and named based on the id of each record as well.

What I am trying to accomplish is this

loop through every link where class = clickshow
Pull the rel attrib that defines the unique id
create a $('#div[clickshow.relAttrib.val]').dialog()

I hope this makes sense.
thanks for the help.

I have a basic understanding of the .each function but not enough to put it together w/o hours of messing up.  I don't mind an hour of messing up - but at this point all I am learning is how to get frustrated :)

thanks and God Bless!

<cfoutput query="qryClients">
<tr><td>
<a name="show#rel_ClientID#" id="show#rel_ClientID#" rel="#rel_ClientID#" class="clickshow">click me</a>
</td></tr>
</cfquery>


<cfoutput query="qryClients">
  <div id="client#rel_ClientID#" style="display:none">
    dialog contents go here
  </div>
</cfquery>

Open in new window

0
Comment
Question by:jtheriau
6 Comments
 
LVL 3

Accepted Solution

by:
FrankoH earned 250 total points
Comment Utility
Hi,

Im not 100% sure on your set up here, but if I understand correctly, then you would do something along these lines.

$(function(){
		
		//Long version
		$(".clickshow").live("click", function(e){
			// Stop anchor click from reloading the page
			e.preventDefault();
			// Pull client id from the anchor rel attribute
			var $clientid = $(this).attr("rel");
			// Concatenate to create related dialog id
			var $dialogid = "#client"+$clientid;
			// Create dialog
			$($dialogid).dialog();
		});
		
		
		// Shorter version
		$(".clickshow").live("click", function(e){
			e.preventDefault();
			$("#client"+$(this).attr("rel")).dialog();
		});
		
	});

Open in new window


I put 2 versions in just so you can see the logic a bit better & a shorter version keeping code tidier.

You dont need to use each to attach an event trigger to each matching element, jquery will do the donkey work for you.

Let me know if thats what you need.

0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
you may want to use .prop or .data rather than attr
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Closing Comment

by:jtheriau
Comment Utility
Thank you !!! That was exactly what I needed.  The long dscription certainly helped me 'get it'  thanks so much!!!!
0
 

Author Comment

by:jtheriau
Comment Utility
Mplungian - I am not sure why I would use one over the other - I just picked the rel attribute b/c I had seen it used elsewhere in the same manner

Thanks

Leakim - Thank you for the link.  It was not the solution I was looking for here - but certainly I can find use for it in another project :)  Thank you

Thank you all for the help and God Bless!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Right. Rel IS an attribute so no need for prop

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
get radio button vale in array 7 35
grab and show facebook pages event calendars 6 40
Problem to picture file 3 37
gif overlay 3 32
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authoriā€¦
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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)

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now