Solved

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

Posted on 2011-09-23
6
313 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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)

770 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