Karmel Zaidan
Karmel Zaidan

Reputation: 173

Uncaught ReferenceError: function is not defined with onchange

I'm trying to access to Update_Price function in JavaScript file when I make any changing on select tag, but unfortunately the Uncaught Reference Error appear. This is my code:

<!Doctype html>
<html>
  <head>
    <script type="text/javascript" src="Form-validation.js"></script>
    </script>
  </head>
  <body>
    <select class="Booking-Form-Group" id="combo-box"  onchange="Update_Price()">
          <option value="1">Single Room</option>
          <option value="2">Double Room</option>
          <option value="3">Twin Room  </option>
          <option value="4">Family Room</option>
          <option value="5">Standard Room</option>
          <option value="6">Meeting Hall</option>
          <option value="7">Conference Room</option>
      </select>
  </body>
</html>

This is my JavaScript code.

function Update_Price(){

    alert('Warning');

    var combo = document.getElementById('combo-box');
    var index = combo.options[combo.selectedIndex].value;

    var value = 0;
    if (index == 1){
        value = 15;
    }
    else if(index == 2 || index == 3){
        value = 25;
    }
    else if(index == 4){
        value = 40;
    }
    else if(index == 5){
        value = 20;
    }
    else{
        value = 60;
    }
    alert(value);

    document.getElementById('price').innerHTML='Total Price is: '.value;

}

Upvotes: 2

Views: 14893

Answers (1)

gurvinder372
gurvinder372

Reputation: 68413

Your problem is this line

document.getElementById('price').innerHTML='Total Price is: '.value;

It should have a concatenation operator + instead of .

document.getElementById('price').innerHTML='Total Price is: ' + value;

Upvotes: 3

Related Questions