Xtremer360 Posted November 23, 2010 Share Posted November 23, 2010 I'm trying to figure out with jquery how I can pass a variable with my jquery code if that's the way I need to do it. The variable I'm wanting to pass is the id of of the menu that way it will have the menu id when it goes to the menuitems page. which I still technically need to get out of the db in my SELECT statement but I can do that. Do I pass it in the a link or do I put it somewhere in the jquery code? <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { echo ' <tr> <td><input type=checkbox class=checkbox /></td> <td>' . $row['menuname'] . '</a></td> <td><a href=# id="menuitems" title="' . $row['menuname'] . ' Structure Items">Menu Items</a></td> <td>' . $row['name'] . '</a></td> <td class=last>' . $row['datecreated'] . '</td> </tr>'; } ?> <script> $(document).ready(function() { $('a', $('td')).click(function() { $('#content').load('mods/' + $(this).attr('id') + '.php'); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/ Share on other sites More sharing options...
trq Posted November 23, 2010 Share Posted November 23, 2010 Its not clear what variable your wanting to pass, but using load(), the simplest way is probably just to attach it to the url.... <script> $(document).ready(function() { $('a', $('td')).click(function() { $('#content').load('mods/' + $(this).attr('id') + '.php?id='$(this).attr('title')); }); }); </script> You could also use the second argument, though it doesn't really matter, both ways will use GET and your data will show up within the $_GET array. I'm sure I've said it before but you really should take a good look at the jQuery manual. http://api.jquery.com/load Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138641 Share on other sites More sharing options...
Xtremer360 Posted November 23, 2010 Author Share Posted November 23, 2010 I've been glancing through it periodically but didn't see anything that would help. I did try to use what you gave me with a small change from title to id and after I did, it wouldn't load anything. Here's the full file. Maybe there's something [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138746 Share on other sites More sharing options...
trq Posted November 23, 2010 Share Posted November 23, 2010 You had an extra }); at the end plus you where missing the concatination operator (I was in my last post too). $(document).ready(function() { $('a', $('div#addform')).click(function() { $('#innerContent').load('forms/' + $(this).attr('id') + '.php'); }); $('a', $('td')).click(function() { $('#content').load('mods/' + $(this).attr('id') + '.php?id=' + $(this).attr('id')); }); }); Working with Javascript you really need to get firebug going. Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138753 Share on other sites More sharing options...
Xtremer360 Posted November 23, 2010 Author Share Posted November 23, 2010 I have FireBug and use it for css but as far as understanding the uses and abilities for things like jquery and/or jquery I don't know. Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138754 Share on other sites More sharing options...
Xtremer360 Posted November 23, 2010 Author Share Posted November 23, 2010 Testing and its still not doing anything. I understand it now however I don't understand why its not atleast loading the page. <script> $(document).ready(function() { $('a', $('div#addform')).click(function() { $('#innerContent').load('forms/' + $(this).attr('id') + '.php'); }); $('a', $('td')).click(function() { $('#content').load('mods/' + $(this).attr('id') + '.php?id=' + $(this).attr('id')); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138757 Share on other sites More sharing options...
trq Posted November 24, 2010 Share Posted November 24, 2010 What is firebug saying? Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138766 Share on other sites More sharing options...
Xtremer360 Posted November 24, 2010 Author Share Posted November 24, 2010 That's just it as far as looking at it for javascript type stuff to debug I don't know what I should be looking for. I'll upload the page. http://defiantwrestling.net/efedmanager/index Look at the menu structures link which is under the site admin drop down on the left. Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138767 Share on other sites More sharing options...
trq Posted November 24, 2010 Share Posted November 24, 2010 Open firebig console. You get: http://defiantwrestling.net/efedmanager/mods/.php 404 Not Found 2.14s Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138778 Share on other sites More sharing options...
Xtremer360 Posted November 24, 2010 Author Share Posted November 24, 2010 Which means? Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138791 Share on other sites More sharing options...
trq Posted November 24, 2010 Share Posted November 24, 2010 Obviously its not getting the file name from wherever its meant to be. I don't really have much time to look through the code, I'm at work. Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138793 Share on other sites More sharing options...
trq Posted November 24, 2010 Share Posted November 24, 2010 Actually, you have the title on the a attribute don't you? Not the td? Within that piece of code 'this' refers to the td element, After all, that was what was clicked. I really think you should take some time out to learn some jQuery basics. We can't really be expected to walk you through every detail. Quote Link to comment https://forums.phpfreaks.com/topic/219598-passing-variables-with-jquery/#findComment-1138795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.