Reputation: 13
I am making a "project calculator" in HTML/javascript for the consultancy business I work in. I need it to show the price of a consultant based on the consultant's title rank. I did this with the select tag and p tag (for showing the price).
I have also added an input box, where number of hours should be filled in. Thereby I need to add the price of the consultant (from the p tag) with the number of hours - this number needs to be shown somewhere on the HTML page.
I found out that I cannot calculate with p values - but I don't know how else I can make this calculation. Maybe there is another solution to displaying the consultant price than the p tag?
<select style="position:absolute; left: 20%;" id = "title1">
<option value = "Consultant">Consultant</option>
<option value = "Senior Consultant">Senior Consultant</option>
<option value = "Principal">Principal</option>
<option value = "Expert Director">Expert Director</option>
<option value = "Partner">Partner</option>
</select>
<button onclick="price1()">Calculate price</button>
<p id="pr1"></p>
<input type="number" id="hours1" placeholder="Number of hours on the project">
Upvotes: 1
Views: 195
Reputation: 61
You can parse an integer from the value of a p tag and make you calculations with that int.
var price = parseInt(document.getElementById("pr1").innerText, 10);
In case you need to calculate also the price for half hours you may parse a float.
Kind Regards
Ruben Kober
Upvotes: 1