Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    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
    
    			});
    		});

  • #5
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •