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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation jquery not passing variables to next page

    This code has evolved on SO but I'm having issues with the code not passing the variables to the next page.

    I have a jquery code that listens for what "folder" the user chooses and then it is supposed to present the information in a div. I moved the ability to choose the folder from being a html select option box to being just links and now the information isn't showing. I believe that it's not passing the variables from the first page to the second page. When I click on the links nothing appears in the div like it did when I had the folder names in a <select> box.


    First page code: (jquery and the php to show the list of folders the user has created)

    Code:
    <script type="text/javascript"> 
    $(document).ready(function () { 
    $(".folders").click(function() { 
    var option = $(this).val(); 
    var selectedUser = $("#thename").val(); 
    $.get("selectfolders.php", {select:option,username:selectedUser},function(data){ 
    $("#theresult").html(data).hide().fadeIn(1000); 
    }); 
    }); 
    }); 
    </script> 
    
    <?
    //The php for listing the folders 
    $thelistquery = mysql_query("SELECT * FROM folders WHERE username='$username'"); 
    while ($lrows = mysql_fetch_array($thelistquery)) { 
    $id = $lrows['ID']; 
    $foldername = $lrows['foldername']; 
    $newfoldername = mysql_real_escape_string($foldername); 
    echo "<a class='folders' value='$newfoldername'>$newfoldername</a>"; 
    }
    ?>

    The variable "username" in the jquery code is from a <input type=hidden> value. I didn't put it in here though.

    Second Page Code: (Gets the variables and uses it to display information on the first page.)

    Code:
    $username = $_GET['username'];
    $theselect = $_GET['select'];
    
    $thelistquery = mysql_query("SELECT * FROM folders WHERE username='$username'");
    while ($lrows = mysql_fetch_array($thelistquery)) {
    $id = $lrows['ID'];
    $foldername = $lrows['foldername'];
    $newfoldername = mysql_real_escape_string($foldername);
    
    if($_GET['select'] == "$newfoldername") {
    //What to display
    }
    }
    ?>

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    If .folders is now simply a div then this:

    Code:
    $(".folders").click(function() { 
    var option = $(this).val();
    will not return a value, since .val() will only return the value of a form field. You'll need to populate option in a different way.

    You should be able to see what data is passed by your .get() by viewing the console in Firebug, or the Network tab in Opera/Chrome/IE developer tools
    Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
    Read Steve Krug's book Don't Make Me Think - essential reading on web usability
    I don't recommend much, but I do recommend Clook for UK web hosting

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    <a> tags don't have a value attribute, they have an href attribute.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Tags for this Thread

    Posting Permissions

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