jQuery returns undefined variable - doesn't take html value

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Wolfie
Forum Commoner
Posts: 37
Joined: Wed Jan 28, 2009 8:40 am
Location: Poland

jQuery returns undefined variable - doesn't take html value

Post by Wolfie »

Hi all

I have this html code (with Smarty) :

Code: Select all

 <div id="menu">    <ul>        {section name="i" loop=$box}        <li value="{$box[i]}"><a href="#" class="menu" >{$box[i]}</a></li>        {/section}        <li><a href="#">Recived</a></li>        <li><a href="#">Filter</a></li>        <li><a href="#">Spam</a></li>    </ul></div> 
And for this I have jQuery function :

Code: Select all

 $("#menu").find('li').click(function() {        $('html').load("index.php", {'mailbox': $(this).find('li').attr('value'),//find('li').val(),                                     'controller' : 'mailbox',                                     'action' : 'mailbox'});    }); 
But when I am looking in firebug the mailbox variable is undefined, I was also trying with find('li').val() (commented part) but the same results....how to fix it ?

And second question, as u can see the load() function loads the content to 'html' but I don't know if it is good solution, cause it should just load the index.php instead of the file which exists before load() call. Is there a better way ?
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: jQuery returns undefined variable - doesn't take html value

Post by kaszu »

Because $(this) is LI, instead of

Code: Select all

$(this).find('li').attr('value')
use

Code: Select all

$(this).attr('value')

Code: Select all

$('html').load
is a really bad solution, why not just change page?
AJAX needs to be used to solve the problem, not to have it just to have it.
Wolfie
Forum Commoner
Posts: 37
Joined: Wed Jan 28, 2009 8:40 am
Location: Poland

Re: jQuery returns undefined variable - doesn't take html value

Post by Wolfie »

Well, but with anchor I cannot pass three variables in one time, can I ?
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: jQuery returns undefined variable - doesn't take html value

Post by kaszu »

Since you are not changing any data, then POST is not needed, better pass data as GET

Code: Select all

<li><a href="index.php?mailbox={$box[i]}&controller=mailbox&action=mailbox" class="menu">{$box[i]}</a></li>
Post Reply