views:

1606

answers:

1

Hello all, I got a problem regarding how to assign a java script variable to a smarty variable. Here is the code snippet.

function getDateInfo(date, wantsClassName)
{                  
    var as_number = Calendar.dateToInt(date); //This as_number is the variable which should be assigned to smarty variable    
}

How can i accomplish this.

any help will be appreciated..

Thanks n advance -- Fero

+4  A: 

You can't assign a client-side value to a smarty variable, as smarty is a templating language that runs on the server. Smarty assignments can only be done on the server-side, that is to say, from PHP. E.g.:

$smarty->assign('timestamp',time());

So what you can do is something like:

    $smarty->assign('timestamp',time()); //in your PHP script

    //in your JS
    var currentTS = {$timestamp};

See http://www.smarty.net/manual/en/api.assign.php

karim79
thanks for your reply karim. but is there any other way to get the value of java script variable and assigning it to smarty.
Fero
Send it to the server using AJAX, retrieve it from $_GET or $_POST and assign it to you smarty variable. If you provide more detail on what you're trying to accomplish (edit your question with more info), you will get a more complete answer.
karim79
great karim, Thanks for ur answer. i got the knot...
Fero