开发者

Assign JavaScript variable to Smarty variable [duplicate]

This question already has answers here: Closed 11 years ago. 开发者_如何学JAVA

Possible Duplicate:

how to assign a javascript variable to a smarty variable

I want to assign a textfield value to Smarty variable using JavaScript and call Smarty function but I could not do it.

Please guide me.


You cannot do that in an easy way. PHP, and by extension Smarty, is parsed and run on the server side before the browser get the data. JavaScript is run on the client side when the browser parses the HTML, CSS and Javascript that the server sent.

You will have to make a new HTTP request in some way, sending the new data. You can do that by reloading the entire web page and sending stuff in the querystring (after ? in the URL), or slightly more advanced by doing an Ajax call from your JS code and make JS do the changes of the page that you desire. The latter is more complex and requires some knowledge of Javascript, but the page does not need to be reloaded in its entirety.


Did you mean something like this?

<script>
var foo_bar = {$foo.bar|escape:javascript};
</script>

Note that, as mentioned above, the value is computed server-side.

UPD. I get it now, you wanted to pass value the other way around. No, that’s not possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜