Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access Smarty value with javascript

    Hi

    someone please let me know the way to access a smarty value with javascript?

    my smarty value is = {$value.url}

    i want to access it like

    Code:
    <script type="text/javascript">
    function load()
    {
    	document.location = '{$value.url}';	
    }
    </script>

    i tried with wrapping code with {literal} {/literal} but it isnt working. can some one correct this please

    sorry for bad english

    Thanks

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    you can’t. (unless we’re talking not about Smarty, the PHP templating engine)

    PHP finished working before JavaScript starts up. The only way JS can interact with PHP is through a HTTP Request. however, you can use PHP (and Smarty) to print out JS code.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got it working by

    {literal}
    <script type="text/javascript">
    function load()
    {
    document.location = '{/literal}{$value.url}{literal}';
    }
    </script>
    {/literal}


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •