Click here to Skip to main content
11,496,146 members (817 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: Javascript HTML
I try to call a java script function from a html check box as follows
<script type="text/javascript">
                var check=val.checked;
<input type="checkbox" id="changeGroup" onchange="changeGroup(this);"/>

But it does not working. Can any one give me, what the problem in this code.
Posted 21-Mar-13 0:52am
Shubham Choudhary at 21-Mar-13 6:35am
hi!!! agav try to onclick instead of onchange

It is working fine.

I don't know the control you have taken for "toGroup".
But I have taken that as a button and tested, the code is working.

When checkbox is checked, the below line will calculate as true.
var check = val.checked;
So, the button will be enabled as per the code below.
document.getElementById("toGroup").disabled = !check; //As !check is false

When checkbox is un-checked, the below line will calculate as false.
var check = val.checked;
So, the button will be disabled as per the code below.
document.getElementById("toGroup").disabled = !check; //As !check is true

Check the Live Demo[^].

agav at 21-Mar-13 10:07am
But still the problem is there.

toGroup is a select associated with bean
<html:select styleId="toGroup" property="toGroup">

The similar code working good in another jsp file.
Tadit Dash at 22-Mar-13 2:21am
I could not get you.
Is it a dropdown ?
the problem solved by changing function name. The function name and id of checkbox cannot be same!
Tadit Dash at 22-Mar-13 3:08am
But it was working with me. You can see the demo I have provided in my answer.
hi friend toGroup is visible false then following try to
<script type="text/javascript">
                var check=val.checked;
sainadhchintha at 21-Mar-13 7:11am
with out function name what it mean. His actual code is working fine.
try these,

function changeGroup(id){
var check=id.checked;

<input type="checkbox" id="changeGroup" onchange="changeGroup(;"/>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 RyanDev 230
2 CHill60 163
3 Sascha Lefèvre 145
4 Sergey Alexandrovich Kryukov 124
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100