Solved

Get value of a html checkbox in the onchange event

Posted on 2013-01-18
10
564 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

617 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