Solved

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

Posted on 2011-09-23
6
317 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
[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
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…
Suggested Courses

624 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