• Resolved Juha Mets?kallas

    (@juhametsakallas)


    This might be a FAQ, but can you read parameter value with javascript?

    Say, you call a shortcode [sc name="mySC" name="Joe"] which contains javascript like this

    
    <script>
    if(name == "Joe")
    {
      …
    }
    </script>
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author vaakash

    (@vaakash)

    Hi @juhametsakallas,

    Shortcoder is unaware of the code or what it does.

    But using “custom parameters” you can replace content dynamically.

    (make sure you don’t use the “name” as the parameter since it is used to identify the shortcode itself)

    <script>
    if(name == "%%username%%")
    {
      …
    }
    </script>

    Now you can insert the shortcode like [sc name="myshortcode" username="Joe"]

    This will insert the code with %%username%% replaced with Joe

    Thanks,
    Aakash

    Thread Starter Juha Mets?kallas

    (@juhametsakallas)

    My use case was a little more complex and I tried to simply it, but it seems I simplified it too much. And of course, after an hour from my posting I came up with a solution, which while not perhaps the prettiest one, works and is reasonably easy to maintain.

    A website has a WPForms form for subscribing a newsletter. Actually there need to be six forms for the same thing. The site has subsections in three languages and it seems that there must be two variants of the form for each language depending on where the form should be displayed on a page, whether at the bottom or at a sidebar (do not ask why, I did not create the site).

    What I ended up doing was six forms (three languages by two CSS settings), but only three shortcodes (for three languages) to output the form title and description and the shortcodes have a custom parameter for picking up the right variant of the form.

    Anyway, thank you!

    PS. This is an awesome plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Reading parameter with javascript’ is closed to new replies.