# Associate function with ranged option selects

**URL:** <https://discourse.gohugo.io/t/associate-function-with-ranged-option-selects/29929>\
**Category:** support\
**Created:** [December 10, 2020, 1:04pm UTC](https://discourse.gohugo.io/t/associate-function-with-ranged-option-selects/29929 "2020-12-10T13:04:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vistad](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/vistad/32/20509_2.png) [@vistad](https://discourse.gohugo.io/u/vistad)\
**Post date:** [December 10, 2020, 1:04pm UTC](https://discourse.gohugo.io/t/associate-function-with-ranged-option-selects/29929/1 "2020-12-10T13:04:18Z")

</div>

I currently have html dropdown option selects for price calculation and I want to replace them with this hugo range dropdown option select solution:

```auto
---
option:
  sizes: ["small","med","large"]
  color: ["red","blue","black"]
---

```

```auto
{{ range $variantName, $value := .Params.option }}
{{ if len $value }} <!-- check if value(array) is not empty -->

<select name="{{ $variantName }}" id="{{ $variantName }}">
  {{ range $v := $value }}
    <option value="{{ $v }}">{{ $v | humanize }}</option>
  {{ end }}
</select>

{{ end }}
{{ end }}

```

```auto
https://discourse.gohugo.io/t/anyway-to-dynamically-have-values-based-in-the-md-params/29906/3

```

My current html option selects look like this:

```auto
<select class="order form-control id="select-1">
	<option value="{{ $resultItem1 }}" selected>{{ .item1 }}</option>
	<option value="{{ $resultItem2 }}">{{ .item2 }}</option>
	<option value="{{ $resultItem3 }}">{{ .item3 }}</option>
	<option value="{{ $resultItem4 }}">{{ .item4 }}</option>
</select>

```

But I have functions that calculate the price for each option - here is the 1st of them:

```auto
{{ $resultItem1 := 0 }}
{{ with .Params.price1 }}
   {{ $resultItem1 = printf "%.2f" (mul $.Params.margin . ) }}
{{ end }}

```

I would be very grateful if someone can tell me how I can range this function together with the option selects to calculate the respective price for each option and put the result into the select value="{{ }}".  
Thank you!
