javascript var to php variable

Discussion in 'JavaScript' started by KillinSprE, Apr 2, 2009.

  1. #1
    I am trying to get the assigned VARs in a javascript to display in a php echo
    here's a relevant portion of the code:

    var colorVar = new Array();
    for( i=1; i<19; i++ ){
    var inputNum = 'input' + i;
    colorVar[ inputNum ] = new Array();
    }
    colorVar['input1'][0] = 'medtablefont';
    colorVar['input1'][1] = 'MEDIUM_TABLE_FONT_COLOR';
    colorVar['input1'][2] = '';
    colorVar['input1'][3] = 'color';
    colorVar['input1'][4] = '#000000';
    colorVar['input2'][0] = 'medtablebg';
    colorVar['input2'][1] = 'MEDIUM_TABLE_COLOR';
    colorVar['input2'][2] = '';
    colorVar['input2'][3] = 'backgroundColor';
    colorVar['input2'][4] = '#E8E8E8';

    I need it to be able to make $text=colorVar['input1'][4] and $bkgrnd=colorVar['input2'][4] so that <? echo $text.' '.$bkgrnd; ?> will have an output of "#000000 #E8E8E8". it has to be this way to conform to other information in the script
     
    KillinSprE, Apr 2, 2009 IP
  2. HolySavior

    HolySavior Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    as long as the JS comes before the php i think that should work. never really tried it that way.

    why not just make the array in php though? it would be quicker and it would make sure everyone sees it even if JS is disabled.
     
    HolySavior, Apr 3, 2009 IP