Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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. –  Vohuman Mar 9 at 8:01
    
@Vohuman can you kindly give an example? –  Raza Chohan Mar 9 at 8:05
    
Please refer to this question. –  Vohuman Mar 9 at 8:07

1 Answer 1

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.