Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-10-2012, 09:09 AM   PM User | #1
tebrown
New to the CF scene

 
Join Date: Sep 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
tebrown is an unknown quantity at this point
Passing variable to javascript modal window.

Hey Guys,

For the last couple of days i've been stumped on this jquery modal that I have been using. The problem i have come across involves passing variables to a jQuery modal dialogue upon a user clicking a link.

At the moment i am running a mysql_query that gets all the fixtures from the database. The results of these are then displayed on a page called schedule.php. Next to each fixture, a user can click the a link called 'edit lineup' which would then open up a modal window(lineup.php).

The link 'edit lineup' on schedule.php has a variable within the url (id). Like this:

Code:
<div id='basic-modal'><a href="schedule.php?id=<?php echo $id; ?>" class='basic'>Edit Lineup</a></div>
What i want to do is pass this id value into the modal window once the user clicks the link. Obviously this is different because the page is not being refreshed.

This is the javascript that opens the modal if it helps.



Code:
	jQuery(function ($) {

		// Load dialog on click
		$('#basic-modal .basic').click(function (e) {
			$('#content-one').modal({
			overlayClose:true,
			opacity:40
			});

			});
			return false;
		});
If anyone could help me out that would be much appreciated.

Cheers
tebrown
tebrown is offline   Reply With Quote
Old 09-10-2012, 02:48 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
This hasn't a thing to do with PHP. Javascript should be capable of pulling the querystring with the link and providing it to the modal window onclick.
Moving from PHP to javascript frameworks.
Fou-Lu is offline   Reply With Quote
Old 09-10-2012, 03:02 PM   PM User | #3
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 941
Thanks: 7
Thanked 95 Times in 95 Posts
WolfShade is an unknown quantity at this point
You could make the source of the modal an iframe and pass along the URL parameter. You'd have to use document.URL to get the url and the query string, then just split the query string; first by ?, then by &, then by =.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 09-10-2012, 03:27 PM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
not sure where you want to use the id in the modal but this is one way to go:


Code:
<div id='basic-modal'><a href="schedule.php?id=<?php echo $id; ?>" rel="<?php echo $id; ?>" class='basic'>Edit Lineup</a></div>


Code:
	jQuery(function ($) {

		// Load dialog on click
		$('#basic-modal .basic').click(function (e) {
                        e.PreventDefault();
                        var Myvar = $(this).find('a').attr('rel');
			$('#content-one').modal({
			overlayClose:true,
			opacity:40
			});
                          //do something here with MyVar

			});
		});
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 09-11-2012, 03:01 PM   PM User | #5
tebrown
New to the CF scene

 
Join Date: Sep 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
tebrown is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
This hasn't a thing to do with PHP. Javascript should be capable of pulling the querystring with the link and providing it to the modal window onclick.
Moving from PHP to javascript frameworks.
How would i go about doing this? - this is the way i would like to do it.

Cheers
tebrown
tebrown is offline   Reply With Quote
Old 09-11-2012, 03:03 PM   PM User | #6
tebrown
New to the CF scene

 
Join Date: Sep 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
tebrown is an unknown quantity at this point
Quote:
Originally Posted by DanInMa View Post
not sure where you want to use the id in the modal but this is one way to go:


Code:
<div id='basic-modal'><a href="schedule.php?id=<?php echo $id; ?>" rel="<?php echo $id; ?>" class='basic'>Edit Lineup</a></div>


Code:
	jQuery(function ($) {

		// Load dialog on click
		$('#basic-modal .basic').click(function (e) {
                        e.PreventDefault();
                        var Myvar = $(this).find('a').attr('rel');
			$('#content-one').modal({
			overlayClose:true,
			opacity:40
			});
                          //do something here with MyVar

			});
		});
Thanks for you reply,

How would i then echo the Myvar variable in PHP? - so i can then use the id to search within a mysql_query.

Cheers
tebrown
tebrown is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:22 PM.


Advertisement
Log in to turn off these ads.