JSFiddle - React, Tailwind, and code Playground

by Michel Plungjan

HTML

<form action="purchase.php" id="form1">
  Promotion code: <input type="text" name="promotion_code" id="prCode" />
  Price: <input type="text" readonly="readonly" 
           name="finalprice" id="fPrice" value="200" />
</form>

JavaScript

var orgPrice = 200;
window.onload=function() {
  document.getElementById("prCode").onkeyup=function(){
    // hardcoding the promocode is NOT recommended
    if (document.getElementById("prCode").value == "12345") {
      document.getElementById("fPrice").value=orgPrice-10;
    }
  }
}