Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am using laravel blade format for my html and I am passing multiple php variables to javascript functions. Now the issue the variables being passed to javascript function could have special characters. Now I want to the javascript function to be as follows:

what I want:

jsFunction("argument1","argument2","argument3")

what I get:

jsFunction('argument1','argument2','argument3')

Now my blade format code is:

<a href="#" onclick="displayBannerInvoice('{{$bannerProperty->property_id}}','{{ $bannerProperty->id }}','{{$bannerProperty->end_date}}','{{$bannerProperty->no_of_days}}','{{$bannerProperty->total}}','{{$bannerProperty->vat_percentage}}')"></a>
share|improve this question
    
Instead of using onclick and string concatenation which is very fragile and error-prone in this case, consider json_encode ing the data and storing the result in JavaScript variables. Then your click event handler set by addEventListenter or ... can easily read the data. – undefined Mar 9 '15 at 8:01
    
@Vohuman can you kindly give an example? – Raza Chohan Mar 9 '15 at 8:05
    
Please refer to this question. – undefined Mar 9 '15 at 8:07
    
change your onclick to: onlick='' instead of onclick="" so it will then be onclick='function("{{$variable}}", "{{$variable}}")' – Uche Dim Nov 19 at 13:36

The best shot is to not reinvent the wheel and try searching :)

There is a package already on github https://github.com/laracasts/PHP-Vars-To-Js-Transformer

It does exactly what you want. Its for Laravel 5 as well as Laravel 4.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.