Answer the question
In order to leave comments, you need to log in
How to display a digital (numerical) value from a checkbox using js?
I have the most banal checkbox, I need that when I click on this square, I would display the tittle value of this checkbox in a certain place (there is a tag <p>
with id = "result"), that is, I marked the checkbox, the amount increased for example by 100r.
I tried it, it gives me the Nan value.
<div class="kadzakad" action="" method="post">
<input title="53" onchange="calc()" type="radio" name="kad_1" id="kad_1">
<label class="kad" for="kad_1"><b>Внутри КАД/</b></label>
</div>
function calc() {
var ter = document.getElementById("kad_1").checked;
var result = document.getElementById("result");
var price = 100;
price =parseInt(ter.title);
result.innerHTML = price;
}
Answer the question
In order to leave comments, you need to log in
var ter = document.getElementById("kad_1").checked; //true или false
price =parseInt(ter.title); // parseInt(undefined)
var ter = document.getElementById("kad_1"),
price = parseInt(ter.title); //А лучше просто +ter.title
function calc() {
var result = document.getElementById("result");
//this и так document.getElementById("kad_1");
result.innerHTML = +this.title;
}
NaN is not a number. Most likely you are not getting a number somewhere.
You can get the title value like this:
$("#kad_1").click(function() {
// получаем значение title
var title = $(this).attr("title");
// вставляем данные в result
$("#result").html(title);
});
var result = +("#result").html() + title;
$("#result").html(result);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question