I need assistance in storing checkbox API values.

I have multiple checkboxes and I can display API values in html when checkbox is checked.

But how do I store the initial value of a checked checkbox and show it in a span?

I currently get “on” value instead of API initial value instead of "on" value.

eg. The value I want is “Breakfast Event” as stored in the API

Below is my code:

<input type="checkbox" id="myCheck1" name="checks" class="round">
<span id="eventTitle" class="results"></span>

//store checkbox values
 $('#myCheck1').on('change', function() {
    $('.results').html(this.checked ? this.value : '');
});

Recommended Answers

You wrote API a few times but didn't call out what API you are working with. To me, JavaScript is just that but not an API. So tell more.

Also I see a lot of repeated questions like "How do I store checkbox values?" but the OP's usually forget to …

Jump to Post

All 4 Replies

You wrote API a few times but didn't call out what API you are working with. To me, JavaScript is just that but not an API. So tell more.

Also I see a lot of repeated questions like "How do I store checkbox values?" but the OP's usually forget to check priors. Example DW search follows:
https://www.daniweb.com/search/index?q=how%20do%20i%20store%20html%20checkbox%20values

I need assistance in storing checkbox API values.

I have multiple checkboxes and I can display API values in html when checkbox is checked.

But how do I store the initial value of a checked checkbox and show it in a span?

I currently get “on” value instead of API initial value.

eg. The value I want is “Faculty Lecture” as stored in the API

Again you write about an API but didn't call it out. Also you write about a Faculty Lecture stored in the API yet again, no mention of the API name or example code. You won't get far repeating your top question.

Read more about asking questions at https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question
As in the posting a question link, you left out what makes a good question.

You simply use the .prop() method to find the checkbox value.
var myval=$('#myCheck1').prop('checked')

Store in some variable and then use the .text() method of span to put the value.
$('.results').text(myval)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.