LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-01-2020, 05:16 AM   #1
droid.c3p0
Member
 
Registered: Sep 2016
Location: Bulgaria
Distribution: MX Linux
Posts: 73

Rep: Reputation: 3
JavaScript function about CheckBox


Creation of a Checkbox inside table cell:
Code:
<td>
    <input type="checkbox" id="chkbx1" name="Chkbx1" value="Checkbox1">
    <label for="chkbx1"> 1</label>
</td>
I am trying to understand is a Checkbox checked or not:
Code:
<script type="text/javascript">
    function Click1()
    {
        var c = document.getElementById("chkbx1").innerHTML;
        if (c !== "checked")
        {
            ........
        }
    }
</script>
Above function does not work the way I expect.
How to correct the function, so it to understand is a Checkbox checked or not ?
 
Old 12-01-2020, 07:17 AM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546

The innerHTML property is for looking at the contents of a tag with children - checked is an attribute which has its own property.

See JS example here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Examples


Last edited by boughtonp; 12-01-2020 at 07:18 AM.
 
2 members found this post helpful.
Old 12-01-2020, 07:17 AM   #3
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
Try:
Code:
<script type="text/javascript">
    function Click1()
    {
        var c = document.getElementById("chkbx1");
        if (c.checked)
        {
            ........
        }
    }
</script>
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Javascript - Calling a Function With a Function Parameter killingthemonkey Programming 9 11-15-2016 05:14 AM
JavaScript: Function that detects click and returns control to calling function slackaddict Programming 2 11-27-2013 02:53 PM
javascript - class / function in function jchambers Programming 3 06-15-2009 10:33 PM
PHP,JAVASCRIPT and CheckBox aznita Programming 2 06-17-2005 04:33 AM
apache user/password checkbox jdubu Linux - Networking 1 05-24-2002 07:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration