Click here to Skip to main content
15,867,308 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.

JavaScript
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<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
                $('td:nth-child(3),th:nth-child(3)').hide();
            });
        });
    </script>
    
    <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>
    
    <script language="javascript" type="text/javascript">
        //go to checkbox web page
        function btn_changeColumns_onClick()
        {
            window.location.href = "checkbox.html"; 
        }
    </script>
    
    
    <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 - http://coursesweb.net/javascript/
            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);
               
            }
            alert(allLabels);
            return selchbox;
        }
)}
        </script>
    
    
</head>
<body>
    <div class="form">
        <p>
            <label>CheckboxList: Happy Friday 
                <?php 
                        //this seems to work
                        $theFrm = ($_POST ["myCheckboxForm"]);
                ?>    
                        getSelectedChbox($theFrm); //**compiler says this is a mis-spelled word
               
            </label>
        </p>
    </div>
<table id="tableone" border="1">
    <thead>
    	<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>
    </thead>
    <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>
    <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>
    <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>
    <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>
     <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>
     <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>
    </tr>
</table>
    <input id="btnHide" type="button" value="Hide Column 2"/>
    <input id="chgColumns" type="button" value="Change Columns Displayed"
            önclick="return btn_changeColumns_onClick()" />
</body>
</html>



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[^]

http://coursesweb.net/javascript/get-value-selected-checkboxes_cs[^]
Posted
Updated 30-May-14 5:25am
v6
Comments
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 :

HTML
<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>
               
            </label>


:)

You just have to add tags....
 
Share this answer
 
Comments
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.

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