click funtion 1/2

i have dice script but i have a issue

see this pic https://i.gyazo.com/52a989aea68643937d6f6c95bc9f8832.png

here 1/2 button i need to work

let me tell you how 2x button work

::js::

function clickdouble() {
  $("#bt_wager").val((parseFloat($("#bt_wager").val())*2).toFixed(8)).change();      
}

::html::

2x

now i wanna make js and html for 1/2 button

Well, not really sure what you need. You show a link (anchor) that calls your function when clicked.
Your sets a value into bt_wager field from the current wager * 2 converted to a fixed number.

What does not work for you? Are you saying that this code works and you want to just make the
one-half version of it? If so, just divide by 2 instead of times 2. Did you try:
[php]
function clickhalf() {
$("#bt_wager").val((parseFloat($("#bt_wager").val())/2).toFixed(???)).change();
}
[/php]
Note that whatever you typed inside the toFixed() part was changed to a smiley, so we could not read it.
If you use preview, you would have seen it changed to a smiley and could have edited it. Not sure what
you need, but, *2 is TIMES 2, and /2 is DIVIDED BY 2… You do not need to use FLOAT’s for this process.
(Unless you have huge numbers.) Normally integer math for division can be done like this:
result = parseInt(num1, 10) / parseInt(num2, 10); or just val(#bt_wager / 2)
Hope that helps!

Added: Also, you are using JQuery. Javascript might be easier to read… Here is a simple example…
[php]
function clickhalf(){
var value1 = document.getElementById(‘bt_wager’).value;
document.getElementById(‘bt_wager’).innerHTML = parseInt(value1 / 2);
}
[/php]
Converted output to INT… Much easier to read and maybe more simple!

Sponsor our Newsletter | Privacy Policy | Terms of Service