Using an input parameter from a web block in Javascript

Using an input parameter from a web block in Javascript

  

I have a web block with an input parameter that I would like to access in the Javascript on this web block, is this possible?

I've seen a variety of questions similar/related to this but most get answers for accessing Javascript variables outside of the JS, which is backwards from what is being asked.

I've attempted to add an input widget to the web block and assigned the parameter to that, then try to access that but get issues there too.

Hi James,

Can you share an example oml how you are approaching this?

imho it's simply using an expression where you assign a local-js-var to the input-var.




James Southall wrote:

I've attempted to add an input widget to the web block and assigned the parameter to that, then try to access that but get issues there too.

Hi James,

I think you are on the correct way, you can use the input and set a JS variable with the input value. You can get the input value like this: $('#LisbonTheme_wt3_block_wtMainContent_wtMyInput').val()

Hope this helps.

Ana


Hi James,

the Javascript property of a Web Block is static, so it cannot have direct access to the input parameter. I'd say J.'s solution would work:

  • Your static JavaScript defines a variable that will hold the value of the input parameter (and eventually use it)
  • in your Web Block canvas you place an Expression with Escape Content set to No and as content JavaScript that assigns the input parameter's value to the JavaScript variable you defined before (string concatenation will be useful). 

hi James,

why not to workaround by putting a parameter on the javascript function in the webblock:

and just called it from the screen that use that web block by supplying the argument:


regards,

bb