Forum

Thread tagged as: Question, Forms

Select Option Values

Hi there,

On my form I have a select field, I need to have the value of each option as the price

so to give you an example my perch code would be like this:

<div>
        <perch:label for="package">Your Package</perch:label>
        <perch:input type="select" id="package" name="package" options="Package One|15,Package Two|22, Package Three|30" label="Your Package" class="venue-select" />
</div>

The thing is when the form is submitted, in the admin area only the values appear. I was wondering if I can actually get the name of the each package displayed as well as the value.

The reason the number has to be on the value is because I am using a jQuery calculator script to calculate a package. https://www.xsanisty.com/project/calx/

Is there a way I could display this in the admin area.

I don't know if im making sense here.

Thanks

Fishtank Creative

Fishtank Creative 2 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

There's no way currently, but it would make a good enhancement.

The best I think you can do is to do with with JavaScript. Something like

$('form').on('submit', function(){
    var option = $('select.venue-select option:selected');
    option.val(option.text() + ': ' + option.val());
    return true;
});

Great thanks, that worked a charm. The only thing though if I have multiple select fields, all the packages are added.

See screenshot to what I mean

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, well you should be able to modify the code to fit your situation.

Cheers, yes it worked if I change the classes for each select field