Click here to Skip to main content
15,350,730 members
Please Sign up or sign in to vote.
5.00/5 (3 votes)
I'm trying to access a function from the body of my table.php file. This file is part php, part javascript. For some reason, the script isn't recognizing the getSelectedChbox function name. It's telling me it's a mis-spelled word. I need to access this function so I can process the form returned from checkbox.html.

<!DOCTYPE html>
<html xmlns="" >
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<meta content="utf-8" http-equiv="encoding"/> 
    <script type="text/javascript" src="js/jquery-1.11.0.js"></script>
    <script type="text/javascript">
        //Used to hide given number row
        $(document).ready(function() {
            $('#btnHide').click(function() {
                // if table has header(th), use this
    <script type="text/javascript">
        //Used to make row editable or not
        $(document).ready(function () {
      $('.editbtn').click(function () {
          var currentTD = $(this).parents('tr').find('td');
          if ($(this).html() == 'Edit') {                  
              $.each(currentTD, function () {
                  $(this).prop('contenteditable', true)
          } else {
             $.each(currentTD, function () {
                  $(this).prop('contenteditable', false)

          $(this).html($(this).html() == 'Edit' ? 'Save' : 'Edit')


    <script language="javascript" type="text/javascript">
        //go to checkbox web page
        function btn_changeColumns_onClick()
            window.location.href = "checkbox.html"; 
    <script type="text/javascript">
        // Returns an array with values of the selected (checked) checkboxes in "frm"
        $(document).ready(function () {
        function getSelectedChbox(frm) {
            // JavaScript & jQuery Course -
            var selchbox = [];        // array that will store the value of selected checkboxes
            var allLabels = [];       // array to store value of all checkboxes, selected and not
            // gets all the input tags in frm, and their number
           var inpfields = frm.getElementsByTagName('input');
           var lblFields = frm.getElementsByTagName('label');
           var allLabelFields = frm.getElementsByTagName('label').innerHTML;
           var nr_inpfields = inpfields.length;

            // traverse the inpfields elements, and adds the value of selected (checked) checkbox in selchbox
            for(var i=0; i<nr_inpfields; i++) {
                if(inpfields[i].type == 'checkbox' && inpfields[i].checked == true) selchbox.push(lblFields[i].innerHTML);
                if(inpfields[i].type == 'checkbox') allLabels.push(lblFields[i].innerHTML);
            return selchbox;
    <div class="form">
            <label>CheckboxList: Happy Friday 
                        //this seems to work
                        $theFrm = ($_POST ["myCheckboxForm"]);
                        getSelectedChbox($theFrm); //**compiler says this is a mis-spelled word
<table id="tableone" border="1">
    	<tr><th class="col1">Header 1</th><th class="col2">Header 2</th><th class="col3">Header 3</th><th class="col3">Header 4</th></tr>
    <tr class="del">
        <td contenteditable="false">Row 0 Column 0</td>
        <td><button class="editbtn">Edit</button></td>
        <td contenteditable="false">Row 0 Column 1</td>
        <td contenteditable="false">Row 0 Column 2</td>
    <tr class="del">
        <td contenteditable="false">Row 1 Column 0</td>
        <td><button class="editbtn">Edit</button></td>
        <td contenteditable="false">Row 1 Column 1</td>
        <td contenteditable="false">Row 1 Column 2</td>
    <tr class="del">
        <td contenteditable="false">Row 2 Column 0</td>
        <td><button class="editbtn">Edit</button></td>
        <td contenteditable="false">Row 2 Column 1</td>
        <td contenteditable="false">Row 2 Column 2</td>
    <tr class="del">
        <td contenteditable="false">Row 3 Column 0</td>
        <td><button class="editbtn">Edit</button></td>
        <td contenteditable="false">Row 3 Column 1</td>
        <td contenteditable="false">Row 3 Column 2</td>
     <tr class="del">
        <td contenteditable="false">Row 4 Column 0</td>
        <td><button class="editbtn">Edit</button></td>
        <td contenteditable="false">Row 4 Column 1</td>
        <td contenteditable="false">Row 4 Column 2</td>
     <tr class="del">
        <td contenteditable="false">Row 5 Column 0</td>
        <td><button class="editbtn">Edit</button></td>
        <td contenteditable="false">Row 5 Column 1</td>
        <td contenteditable="false">Row 5 Column 2</td>
    <input id="btnHide" type="button" value="Hide Column 2"/>
    <input id="chgColumns" type="button" value="Change Columns Displayed"
            önclick="return btn_changeColumns_onClick()" />

So my question is, how do I get it to recognize the function name?

Helpful links I've been looking at are:

Beginner's Guide to HTML5 & CSS3 - Formidable Forms with HTML5[^]

Beginner's Guide to HTML5 & CSS3 - Server Side Story[^][^]
Updated 30-May-14 5:25am
Sampath Lokuge 30-May-14 9:05am
Why have you used so many $(document).ready() methods ? Can't you put everything in one method ?
MichCl 30-May-14 9:41am
I wrote them separately so they still have separate document ready methods. I'll look into trying to get them all under one document ready method, but they are all separate functions.

1 solution

Try following code :

<label>CheckboxList: Happy Friday 
                <?php <br mode="hold" /?>                        //this seems to work
                        $theFrm = ($_POST ["myCheckboxForm"]);
                        <script> getSelectedChbox($theFrm); //**compiler says this is a mis-spelled word</script>


You just have to add tags....
Abhishek Pant 30-May-14 9:12am
I think you caught the mistake.
HardikPatel.SE 30-May-14 9:20am
Yap.... :)
MichCl 30-May-14 9:59am
@Abhishek Pant and @HardickPatel89 - There are still plenty of mistakes. ;)
Abhishek Pant 30-May-14 10:20am
Okay,Good luck for further, try to debug using firebug on design page
MichCl 30-May-14 9:19am
Thank you so much!!! It's accepting the method there now.
HardikPatel.SE 30-May-14 9:22am
Oaky.... & best of luck for further... & that mistake was there because you were calling javascript method in HTML tags...
Nice answer bro. :)


HardikPatel.SE 30-May-14 9:23am
Thanks buddy.... :)
Welcome and your Profile looks good. You have done some CSS magic. Please make it more attractive when you get time. I will then just copy the code to design my profile. :P :D

HardikPatel.SE 30-May-14 9:28am
Yap sure.... :)
HardikPatel.SE 30-May-14 9:32am
Yap sure... & thanks for praise.... :)
Welcome buddy. :)

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900