Jump to content

Passing variables with jquery?


Xtremer360

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.