How to pass literal parameter to included js?


Majidi Karachi

How to pass literal parameter {$currchoice.id}to js? I have the following currency picker and I need it to pass the selected value to javascript as the param (currency=2)is(currency={$currchoice.id})

    <!-- Currency -->
   {if !$loggedin && count($currencies) > 1}
       <div class="pull-right nav">
           <a href="#" class="quick-nav" data-toggle="popover" id="currencyChooser"><i class="fa fa-usd"></i> {$LANG.choosecurrency} <span class="caret"></span></a>
           <div id="currencyChooserContent" class="hidden">
               {foreach from=$currencies item=currchoice}
                   <img src="{$BASE_PATH_IMG}/flags/{$currchoice.code|substr:0:2|strtolower}.png"> <a href="{$currentpagelinkback}currency={$currchoice.id}">{if $currency.id eq $currchoice.id}<u>{/if}{$currchoice.code}</u></a>
               {/foreach}
           </div>
       </div>
   {/if}

<script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly&currency=2"></script>
top master

You seem to have a popover-menu where the user can select a currency and then ask how to add another script based on the user's choice.

Well, if you prefer to refresh the page, just pass the URL parameter from the controller to the view, like:

public function getMyView($request) {
    // TODO: replace 0 with your default currency-id.
    return view('path.to.view')
        ->with('selectedCurrency', $request->input('currency') ?? 0)
}

and use it in the view like:

<script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly&currency={{$selectedCurrency}}"></script>

However, if you don't want to refresh every time the user clicks, then:

  • <script ...Remove the thing completely from your view .
  • Add JQuerycode (or something similar) to find the selected value (e.g. currency ID).
  • Finally, scriptuse JavaScript.

Note that the second approach requires your entire JS (and content that depends on it) to support lazy loading (without causing errors).

Related


Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

How to pass js parameter to CSS style

Kubelius I'm creating a web service using Angular and Spring Boot and I'm using cdkDrag to place some images around the workspace. I want to keep the image in the same place after refreshing the browser. After each drag and drop, I save each image coordinate i

How to pass js parameter to CSS style

Kubelius I'm creating a web service using Angular and Spring Boot and I'm using cdkDrag to place some images around the workspace. I want to keep the image in the same place after refreshing the browser. After each drag and drop, I save each image coordinate i

How to pass js parameter to CSS style

Kubelius I'm creating a web service using Angular and Spring Boot and I'm using cdkDrag to place some images around the workspace. I want to keep the image in the same place after refreshing the browser. After each drag and drop, I save each image coordinate i

How to pass parameter message as text in openpgp JS

AWAY What I am trying to do: Get some Azure Storage blobs from the container DIDE and encrypt them with RSA 2048 and upload them into other containers called encrypted -dide These blobs are downloaded via streaming (well done by Microsoft here https://docs. mi

How to pass js parameter to CSS style

Kubelius I'm creating a web service using Angular and Spring Boot and I'm using cdkDrag to place some images around the workspace. I want to keep the image in the same place after refreshing the browser. After each drag and drop, I save each image coordinate i

How to pass js parameter to CSS style

Kubelius I'm creating a web service using Angular and Spring Boot and I'm using cdkDrag to place some images around the workspace. I want to keep the image in the same place after refreshing the browser. After each drag and drop, I save each image coordinate i

How to pass js parameter to CSS style

Kubelius I'm creating a web service using Angular and Spring Boot and I'm using cdkDrag to place some images around the workspace. I want to keep the image in the same place after refreshing the browser. After each drag and drop, I save each image coordinate i

How to pass js parameter to CSS style

Kubelius I'm creating a web service using Angular and Spring Boot and I'm using cdkDrag to place some images around the workspace. I want to keep the image in the same place after refreshing the browser. After each drag and drop, I save each image coordinate i

Typescript - pass interface literal to function parameter

Paul Redmond I want to use an interface to set data types and then call them in a function while setting default values without passing the data . I am getting the after canvas error ',' expected.in the function . Can't I call it that? // Options interface opt

Typescript - pass interface literal to function parameter

Paul Redmond I want to use an interface to set data types and then call them in a function while setting default values without passing the data . I am getting the after canvas error ',' expected.in the function . Can't I call it that? // Options interface opt

Typescript - pass interface literal to function parameter

Paul Redmond I want to use an interface to set data types and then call them in a function while setting default values without passing the data . I am getting the after canvas error ',' expected.in the function . Can't I call it that? // Options interface opt

Typescript - pass interface literal to function parameter

Paul Redmond I want to use an interface to set data types and then call them in a function while setting default values without passing the data . I am getting the after canvas error ',' expected.in the function . Can't I call it that? // Options interface opt

Typescript - pass interface literal to function parameter

Paul Redmond I want to use an interface to set data types and then call them in a function while setting default values without passing the data . I am getting the after canvas error ',' expected.in the function . Can't I call it that? // Options interface opt

How to pass var to included module?

dsp_099 It's probably simple, but I'm a little confused about using ruby include: app.rb: class Controller @template_ext = '.slim' def template_ext '.slim' end include RenderingHelpers end rendering_helpers.rb: module RenderingHelpers def rende

How to pass var to included module?

dsp_099 It's probably simple, but I'm a little confused about using ruby include: app.rb: class Controller @template_ext = '.slim' def template_ext '.slim' end include RenderingHelpers end rendering_helpers.rb: module RenderingHelpers def rende

How to pass var to included module?

dsp_099 It's probably simple, but I'm a little confused about using ruby include: app.rb: class Controller @template_ext = '.slim' def template_ext '.slim' end include RenderingHelpers end rendering_helpers.rb: module RenderingHelpers def rende

How to pass literal value to node?

Anton Kirilenko I have a function def do_something(input_data, column: int): # Do something with one column of the data Now I need to create a node, but I can't do it node(do_something, ["input_data", 1], "output"). How to put constant value into node? A

How to pass a function to an array literal?

other How can I pass an array without making it a separate variable? For example, I know this works: class Test{ public static void main(String[] args){ String[] arbitraryStrings={"foo"}; takesStringArray(arbitraryStrings); } public

Pass a string as parameter in JS

Ethanol It's simple, I'm trying to insert a value that takes a string as a parameter. Let's take an example: const stringName = "User". My goal is to activate a function that will be called, User.find();I tried the following without success: stringName.find()b

Pass a string as parameter in JS

Ethanol It's simple, I'm trying to insert a value that takes a string as a parameter. Let's take an example: const stringName = "User". My goal is to activate a function that will be called, User.find();I tried the following without success: stringName.find()b

Pass literal property value to angular js directive

Dave I'm having some trouble understanding how property values work in AngularJS directives. No matter what I try, the literal property values appear undefinedwhen I try to use them in the directive controller. Say in my HTML, I call a directive like this: <di