jquery - Incrementing a VTL variable in javascript function -


<script>         var count_security = 0;     #set($count_security = 0)        function increment() {             count_security++;         #set($count_security = $count_security + 1)         alert(count_security);         alert($count_security);         } </script>  <html>     <input type="button" onclick="increment" /> </html> 

when call above function on click of button "$count_security" variable incrementing once.its not incrementing further.

please if doing wrong. raghav

this because of have 2 contexts consider

  • the rendering context (velocity/vtl)
  • the execution context (browser/client)

so when renders have 1 execution in velocity engine execute velocity logic increments $count_security. rendered literal value output.

the var count_security javascript client variable can altered , updated client.

your velocity #set() code not rendered output "set". #set vtl function , not alter output stream.

i hope makes sense.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -