I have this javascript code in php document:
var product=0;
function add(){
if (product<10) {
product++;
}
document.getElementById('display').innerHTML = product;
document.getElementById('display1').value = product;
}
function rem(){
if (product>1){
--product;
}
document.getElementById('display').innerHTML = product;
document.getElementById('display1').value = product;
}
var place=0;
function addplace(){
if (place<10) {
place++;
}
document.getElementById('display_place').innerHTML = place;
document.getElementById('display_place1').value = place;
}
function remplace(){
if (place>1){
--place;
}
document.getElementById('display_place').innerHTML = place;
document.getElementById('display_place1').value = place;
}
Then I have this html code to display vars:
<button style="background-image: url('files/arrow_down.png');" type="button" onClick="rem()"></button>
<button style="background-image: url('files/arrow_up.png');" type="button" onClick="add()"></button>
<div id="display" name="product">
<script type="text/javascript">document.write(product);</script>
</div>/10</div>
<input type="hidden" id="display1" name="display1">
<button style="background-image: url('files/arrow_down.png');" type="button" onClick="remplace()"></button>
<button style="background-image: url('files/arrow_up.png');" type="button" onClick="addplace()"></button>
<div id="display_place">
<script type="text/javascript">document.write(place);</script>
</div>/10</div>
<input type="hidden" id="display_place1" name="display_place1">
So, I display "product" var in "display" div and send the value from "display1" div through form.
Same with "place" var, with "display_place" div and "display_place1".
Now, I need to display this value:
(product + place)/2
Can someone suggest how can I do this? I'm not familiar with JS.
Thanks
where you want to display that value?? you can simply make a div named product_place
and input field named product_place1
and use this code:
function show(){
document.getElementById('product_place').innerHTML = (product + place)/2;
document.getElementById('product_place1').value = (product + place)/2;
}
The HTML part would be like this:
<button type="button" onClick="show()">show</button>
<div id="product_place">
<script type="text/javascript">
document.write((product + place)/2);
</script>
</div>
<input type="hidden" id="product_place1" name="product_place1">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.