Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get value of a html checkbox in the onchange event

Posted on 2013-01-18
10
Medium Priority
?
595 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

972 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