SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Boot Straps's Avatar
    Join Date
    Aug 2005
    Location
    In the flat lands of Montana(USA)
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Array Add & Subtract

    I have a array that holds 24 items (hour in a day). The table is make of week day and hours. Monday is the only day I got going so far. I trying to make it that when you click on specific hour for a day it does two thing. One is change of the cell color, which I'v done and two is that I can get an array of hightlighted cells to feed to php in a hidden form field. Also the array add and Subtract items when clicked or clicked again to remove hightlight. Number two is where I am stuck.

    PHP Code:
    var mycars = new Array(25);

    function 
    testResults (mycarsidfieldfield2) {

        if(
    mycars[id] == id 'on' ){
            
    //mycars[id] = id;
        
    } else {
            
    mycars[id] = id;
        }
        
        
        var 
    quote "";
        for (var 
    1mycars.lengthi++){
        
                if(!
    mycars[i]){
                    
    //mycars[i] = id;
                    //quote += mycars[i] + "u ";
                    
    quote += ". ";
                } else {
                    
                    
    // mycars.splice(i,1,i " on");
                    
    quote += mycars[i] + " ";
                    
                    if(
    mycars[i]==id 'on'){
                        
    //quote += id;
                        
    quote += "_r ";
                        
    quote += mycars.splice(i0"v");
                        
    //mycars[i] = "v";
                    
    }
                    
                    if(
    mycars[i]==id) {
                        
    mycars[id] = id 'on';
                    }                
            }        
        }
        var 
    len mycars.length
        
    len += "Length is " len;
         
        
    field.value quote;
        
    field2.value len;

    The table cells have this form an onClick:
    PHP Code:
    testResults(mycarsthis.idmyform.remLenmyform.remqaz); 
    I have tryed creating to array with no items in it- nothing ex(new Array()).
    tryed having the function create the array- nothing.

    I can get in the items to add to the array but I cant get them out when needed. The splice will not work right. If it takes out the item it then the rest of the array index go down by 1. I tryed to reset th item by splice(i, 0, "some var") and nothing works.

    Thank you for any thought on getting me in the right road.

    Boot Straps
    Attached Files Attached Files
    Boot Straps

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Boot Straps View Post
    I can get in the items to add to the array but I cant get them out when needed. The splice will not work right. If it takes out the item it then the rest of the array index go down by 1. I tryed to reset th item by splice(i, 0, "some var") and nothing works.
    If you want the array item to still exist, you can just set the array item to false, or to the initial value of that array item, undefined.

    mycars[i] = false;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast Boot Straps's Avatar
    Join Date
    Aug 2005
    Location
    In the flat lands of Montana(USA)
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was it

    thank you

    Boot Straps
    Boot Straps


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •