Solved

Get value of a html checkbox in the onchange event

Posted on 2013-01-18
10
519 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now