Link to home
Start Free TrialLog in
Avatar of pmac38CDS
pmac38CDS

asked on

Get value of a html checkbox in the onchange event

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
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

var bChecked = isAOI.checked;

alert(bChecked);
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);">
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

Avatar of pmac38CDS
pmac38CDS

ASKER

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
What are you trying to do here? The input you have shown is a text box. Can  you supply the code for UpdateSFValue()?
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
Where do you want to pass the true/false result of that function?
ASKER CERTIFIED SOLUTION
Avatar of pmac38CDS
pmac38CDS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You should then assing the input labeled box the returned value, I guess.
This solution worked.