#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    5
    Rep Power
    0

    To select a cell almost finished


    I have a table of colors and I want that the user be able of selecting a cell and the page looks for the color, I got this already, but my problem now is that when the elements are found and the table of the colors has a cell selected, if the user wants to change the color clicking in other cell, the last cell is holding with the border changed(is what I did to realise that is selected)at least that the user clicks again in the same cell selected before, to not select the two cells. What I want is that the first cell selected will not selected when you click in another one, like in the beginning of the searching, the problem I think is that the value is saved in the S_SESSION comand, and maybe this why select both cells, the cell saved and the new selected, but It shouldn't be like this because to select the cell I use a script so... U set the code here to show:

    My filter color:
    PHP Code:
    //Color
    $ColorFilter='';

    if (isset (
    $_POST['colorcar'])) {
        
    $ColorInput $_POST['colorcar'];
    } elseif (isset( 
    $_SESSION['filter']['colorcar'] )) {
        
    $ColorInput $_SESSION['filter']['colorcar'];
    } else {
    // Nothing
    }

    if (isset(
    $ColorInput)) {
            
        if (
    $ColorInput !=''){
            
    $_SESSION['filter']['colorcar'] = $ColorInput;
            if(
    $DataFilter!="") {
                
    $DataFilter .= " AND ";
            }
            
            foreach (
    $arrColor as $CarColor) {
                if (
    $CarColor["ClassColor"] == $ColorInput) {
                    
    $ColorFilter $CarColor["body_colorgroup_id"];
                }
            }
            
    $DataFilter .= "Body_colorgroup_id = " $ColorFilter ." ";
        }
    }else {
        
    $ColorInput ''

    My filter color showed per screen tothe users:
    PHP Code:
    <label for="ColorInput"><?php echo $arrMainPage[$MainPageColor]["TextHeader"]; ?></label>
                                    <table name="ColorInput" id="ColorsTable" >
                                        <tr>
                                        <?php    
                                            $intCount 
    1;
                                            
    $intHalf =  count($arrColor)/2;
                                                
                                            foreach (
    $arrColor as $Color){
                                                
                                                if (
    $Color["body_colorgroup_id"] == $ColorFilter ) {
                                        
    ?>            <td onclick="press(this)" name="ColorInput" style ="border:3px solid black"  value="<?php echo $Color["body_colorgroup_id"]; ?>" class="<?php echo $Color["ClassColor"]; ?>" title="<?php echo $Color["colorDescription"]; ?>"></td>
                                        <?php    } else {
                                        
    ?>            <td onclick="press(this)" name="ColorInput"  value="<?php echo $Color["body_colorgroup_id"]; ?>" class="<?php echo $Color["ClassColor"]; ?>" title="<?php echo $Color["colorDescription"]; ?>"></td>
                                        <?php    }    
                                                if (
    $intCount >= $intHalf) {
                                        
    ?>
                                        </tr>
                                        <tr>
                                        <?php        $intHalf $intHalf*2;
                                                }    
                                                
    $intCount++;
                                            }
                                            
    /*press(<?php echo $ColorFilter; ?>);*/
                                        
    ?>    
                                        </tr>
                                    </table>                        
                                    <input type="hidden" id="colorcar" name="colorcar" value="" />
    And my javascript function to select the cell, that I know that this is the part of the forum of PHP but I didn't find part o put PHP+Javascript sorry:

    Code:
    <script type="text/javascript">
    			//Select a cell of the table colors
    			var cell = null;
    			function press(obj) {
    				obj.style.border = '3px solid black';
    			  	if (cell != null && cell != obj){
    					cell.style.border = '';
    			  	}
    			  	cell = obj;
    			 	$("#colorcar").attr({
    				    value: cell.className
    				})
    			}
    <script>
    Thank you very much
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    function press() needs to clear the borders on all the cells before setting the border on the selected cell.

    Moving to the javascript forum, your PHP is irrelevant to this problem.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    5
    Rep Power
    0
    Originally Posted by ManiacDan
    function press() needs to clear the borders on all the cells before setting the border on the selected cell.

    Moving to the javascript forum, your PHP is irrelevant to this problem.
    I have already repaired it adding this ID="selected-color" to the first part of my IF. And changing and setting my script in this way:

    Code:
    //Select a cell of the table colors
    			var cell = document.getElementById('selected-color');
    			if (cell) {
    				press(cell);
    			}
    			
    			function press(obj) {
    				obj.style.border = '3px solid black';
    			  	if (cell != null && cell != obj){
    					cell.style.border = '';
    			  	}
    			  	cell = obj;
    			 	$("#colorcar").attr({
    				    value: cell.className
    				})
    			}
    And setting my script at the end of the code instead of in the head.

    I hope this will be useful for other people.

    Thanks.

    Regards.

IMN logo majestic logo threadwatch logo seochat tools logo