Jump to content

Recommended Posts

I have checkbox function that creates a checkbox list  from my database. I also have a map that I want onclick to check the checkbox align with that section of the map. So if you click Bominvile on the map the checkbox for Bominville gets checked/unChecked.

[FUNCTION CALL] (From db.php)

/ This  will create a CHECK BOX based on the property/value pairs in table AND the toggle all checkbox.
function buildCheckBox($table, $prechecked)
{
        $conn = db_connect(); // establish connection
        $sql = "SELECT property, value FROM ".$table."";
        $results = pg_query($conn, $sql);
        
        //THIS LOOP ONLY RUNS ONCE ON PAGE LOAD. JUST TO DISPLAY
        // THE REORDS IN THE CITY DB TABLE.
        while ($record = pg_fetch_array($results))
        {
                
            $checked = ($prechecked == $record['value'])?"checked=\"checked\"":"";
            echo '<input type="checkbox" name="'. $table.'[]" ' .$checked.' value="'. $record['value'] .'">'. $record['property'] .'<br/>';
            
        }
        //echo "show me whats record ". $record['property']. "<br/>";
        
        
}

[/FUNCTION]


<script language="javascript">
function myclick(whichone)
{
  if (document.getElementById(whichone).checked == true)  {
    document.getElementById(whichone).checked = false;
  } else {
    document.getElementById(whichone).checked = true;
  }
}
</script>


          <tr>
                    <td class="left">
                        <input type="checkbox"  id="city_toggle" onclick="cityToggleAll();" name="city[]">City Toggle All<br/>
                            <!-- FUNCTION CALL TO LOOP THROUGH TOGGLING CHECK BOXES ON/OFF-->
                        <?php echo buildCheckBox('city', $selected_city);?>
                        
                        <input type="checkbox" id="city[]"><br>
                        
                        
                </td>
          
                    <td><img src="pictures/durham_mapgoodbeforewhitby.png" alt="durham_map" width="417" height="340" usemap="#map1">
                    <a href="#" onClick="myclick('city[]')">
                    <map name="map1">
                        
                    <area shape="poly"
                        coords="193,207,284,207,391,214,190,287,260,299,300,307,344,310,389,322"  href="#" id="city[]" title="Bowmanville" alt="Bowmanville" />
                    
                    </map>
                    </a><br>
                </td>
            </tr>
 
Link to comment
https://forums.phpfreaks.com/topic/283486-php-checkbox-onclick-with-function-call/
Share on other sites

got it to work but now the checkbox goes away after onClick

 

 

 
                              
                </td>
          
                    <td><img src="pictures/durham_mapgoodbeforewhitby.png" alt="durham_map" width="417" height="340" usemap="#durhammap">
                    
                            <map name="durhammap">
                                                    
                                    <area shape="poly"
                                        coords="193,207,284,207,391,214,190,287,260,299,300,307,344,310,389,322"  href="?city=Bowmanville" onClick="myclick('Bowmanville')" id="Bowmanville" title="Bowmanville" alt="Bowmanville" />
                                    
                            </map>    <br>
    
                </td>
 

ok fixed that too by removing tye href. The only think now how will the user know that that part of the map is clickable :(

 

 

 

                    <td>
                    
                    <img src="pictures/durham_mapgoodbeforewhitby.png" alt="durham_map" width="417" height="340" usemap="#durhammap">
                    
                            <map name="durhammap">
                                                    
                                    <area shape="poly"
                                        coords="193,207,284,207,391,214,190,287,260,299,300,307,344,310,389,322"  onClick="myclick('Bowmanville')" title="Bowmanville" />
                                    
                            </map>    <br>
    
                </td>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.