Page 1 of 1

jQuery returns undefined variable - doesn't take html value

Posted: Sat Oct 10, 2009 11:05 am
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 ?

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

Posted: Sun Oct 11, 2009 8:49 am
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.

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

Posted: Mon Oct 12, 2009 8:52 am
by Wolfie
Well, but with anchor I cannot pass three variables in one time, can I ?

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

Posted: Mon Oct 12, 2009 11:09 am
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>