2

Let's assume I have a “products” channel which contains 3 fields: price(number), discount(integer 1 to 100), discounted_price(number).

Is there a way to populate the discounted_price field in CP, based on price - (price * discount / 100)?

1 Answer 1

1

You'll want to handle this using jQuery/JavaScript in your field's instructions.

You can include HTML in the Instructions field for your custom field. So you can include:

<script type="text/javascript">
// Do some stuff
</script>

You can set your code to fire onblur on your fields, so that every time a field is updated, the JS runs, and calculates the value for the other field.

You can do a View Source on the entry screen to find all the field references you need for your jQuery code.

2
  • 1
    This is rather interesting… fairly brilliant solution. I didn't know the description field accepted html/jscript. I'll test it.
    – Milksamsa
    Mar 8, 2013 at 15:24
  • 1
    It's a fairly common solution once it's realized :) Mar 8, 2013 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.