How can I dynamically change product price depending on values entered in a text field?

RapidCart_Tips_and_Tricks_icon.png

Previous: How Can I set a RapidCart for donations

Example

I want to sell memberships depending on annual income.
If customer's income is below $4000/year, membership is free, otherwise is $1 for each thousand.

Solution

Create a new product.
Add a text field option.
Enable Custom Layout in Options->Style window.
Add the following code to the bottom.

<script type="text/javascript">

$$("#rcItem%ID% input[type=button]").each(function (el) {

    el.disabled = true;

});

$$("#rcItem%ID% input[name=rcItemOptionValue]").addEvent("keyup", function () {

    var price = 0;

    $$("#rcItem%ID% input[type=button]")[0].disabled = true;

    if (!isNaN(this.value) && this.value != 0 && this.value != "") {

        var fee = Math.floor(this.value / 1000);

        if (fee > 4) {

            price = fee;
            $$("#rcItem%ID% input[type=button]")[0].disabled = false;

        }

    }

    $$("#rcItem%ID% input[name=price]")[0].value = price;
    RapidCartUtilities.updatePrice(%ID%);

});

</script>

Next: Adding a "More Info..." in Description field