Make javascript script get value from input dynamically

I have a script in which the logic is working properly but only on the “Page is loaded” workflow.

Basically this script is used to compare two lists and return a value from one of them based on the idex got from a dropdown value.

// get option list
var optionList = "Search for product_options:each item's options".split(",");
// get price list
var addPriceList = "Search for product_options:each item's add_price".split(",");
// get price value from dropdown  <<<HERE >>>>
var dropDownValue = document.getElementById("dropdown").value

function getPrice(string){
    // format bad formatted string from bubble dropdown value.
    var formattedDropdown = string.replace(/(^"|"$|\\"|\')/g, '')
    // get index on optionList based on dropdown value treated.
    var index = optionList.indexOf(formattedDropdown)
    // return price compared with the same index of option
    return addPriceList[index]


Since this dropdown has a default value, when the script “run javascript” is added to “Page is loaded” it gets this “default value” from the dropdown not making the update when I change the value from it.

Therefore, How can I make this script updates the value every time I change it from the dropdown? It seems that “run javascript” only works on “Page is loaded” statically, since I tried to place it in other workflow other than “Page is loaded”. Is that right? There is other way I can perform it? thank you.

1 Like

You can put the Run Javascript action in a workflow when Input’s Value is Changed

1 Like

Perfect. That is what I did and it worked.

For other users, make sure to not leave a default value that will be evaluated. Leave the default value empty or add a message instead to not give usability error.

This topic was automatically closed after 70 days. New replies are no longer allowed.