Solved

Get value of a html checkbox in the onchange event

Posted on 2013-01-18
10
547 Views
Last Modified: 2013-02-10
I have an html checkbox called isAOI. I want to be able to get the value in the onchange event. How do I go about doing so ?

Thanks,
Aditya
0
Comment
Question by:pmac38CDS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 38793617
var bChecked = isAOI.checked;

alert(bChecked);
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 38793626
If you wanted a function to get this then you could do:

<script>
function cbCheck(oFld)
{
  alert(oFld.checked);
}
</script>

Then in your HTML:

<input type="checkbox" name="isAOI" value="" id="isAOI" onchange="cbCheck(this);">
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38793728
jQuery test page : http://jsfiddle.net/F27HB/

$(document).ready(function() {

$(":checkbox[name='isAOI']").change(function() {
       var checkbox_Value = $(this).val();
       alert( checkbox_Value );
})

});

Open in new window

0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 1

Author Comment

by:pmac38CDS
ID: 38793784
Here is what I have
var input = '<input type="text" name="special" value="' + text + '" size="' +size +'" onchange="UpdateSFValue(' + intId + ',this.value)">';

No matter if the checkbox is checked or unchecked it passes the default value to the UpdateSFValue method.

Aditya
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 38793797
What are you trying to do here? The input you have shown is a text box. Can  you supply the code for UpdateSFValue()?
0
 
LVL 1

Author Comment

by:pmac38CDS
ID: 38793834
Sorry about that
var input = '<input id="isAOI" type="checkbox"  size="' + size + '" onchange="UpdateSFValue(' + intId +' ,this.value)">Is AOI?';

The UpdateSFValue method is something that is pretty specific to our system.

Aditya
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 38796206
Where do you want to pass the true/false result of that function?
0
 
LVL 1

Accepted Solution

by:
pmac38CDS earned 0 total points
ID: 38854484
This is what I did
function MakeListboxInput(intId, text, size) {
    // use UpdateSFValue or UpdateSFValueAndRefresh in your onchange event handler
    var input;
    if (text == "") {
        input = '<input id="isAOI" type="checkbox" checked="checked" value="true"  size="' + size + '" onclick="UpdateSFValue(' + intId + ',this.value)">Is AOI?';
    }
    else {
        input = '<input id="isAOI" type="checkbox" value="" size="' + size + '" onclick="UpdateSFValue(' + intId + ',this.value)">Is AOI?';
       
    }

    return input;
}
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 38854505
You should then assing the input labeled box the returned value, I guess.
0
 
LVL 1

Author Closing Comment

by:pmac38CDS
ID: 38872612
This solution worked.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question