0

I want 15% discount to be displayed automatically on the webpage once the user selects SE15 as the discount code(when the function is called)
this is the code i have, its not working, what could be the problem

<script type="text/javascript">
function getDiscount(){
var discount_code=document.orders.discount_code.options[document.orders.discount_code.selectedIndex].value;
var discount=document.orders.discount.options[document.orders.discount.selectedIndex].value;
var answer=document.orders.answer.value;

if(discount_code=="SE15")
discount=answer-(answer/100*15)
else
discount=0

document.orders.answer.value= "$ " + discount
}
</script>

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Airshow
0

You could try this approach:

function getDiscount(x, containerId){
  var menu = document.getElementById('discount_code');
  var container = document.getElementById('containerId');
  if(menu && container){
    var discount = Number(menu[menu.selectedIndex].value)/100;//option value must be "15", not "SE15".
    container.innerHTML = x * (1 - discount);
  }
}

Then control the detailed behaviour by supplying suitable arguments where getDiscount() is called.

Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.