Solved

Get value of a html checkbox in the onchange event

Posted on 2013-01-18
10
525 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding Special HTML Characters using Javascript? 2 23
jquery datepciker end date add 6 days 6 33
Jquery 10 19
"Pause" execution of javascript function for x miliseconds 2 21
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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now