Solved

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

Posted on 2011-09-23
6
312 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
ID: 36592256
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
ID: 36593557
you may want to use .prop or .data rather than attr
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36593665
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Closing Comment

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

Author Comment

by:jtheriau
ID: 36599254
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
ID: 36600771
Right. Rel IS an attribute so no need for prop

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

919 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

16 Experts available now in Live!

Get 1:1 Help Now