How do I pass an array variable from a php function into a javascript function?

I can pass it if it's just a variable but when it's an array, then the javascript can't read it.

From PHP:
<input type='button' onClick='Cycle(" . $sAllEventID . ")' value='Check Subtotal'>

To Javascript:
function Cycle(arrAllEventID) {

Could you please provide some code. Somebody suggested that I should "echo" into Javascript but I didn't know what that would look like. Thank you!

Andrea

    I'm not so sure on what you mean. But for ex. if you wished to pass from a basic array into the js do it like this.

    <?
    // i'm putting a very brief array here with 5 items
    $my_array = array("one", "two", "three", "four", "five");
    
    // now to output the javascript, ie. print it as html into your browser
    // all that needs to be done is to echo and refer to the items within the 
    // array (my_array). i'll do it for both one item and the entire array.
    
      // for one item do this
      echo "<input type='button' onClick=Cycle(". $my_array[0].")'value='Check Subtotal'>";
    
      // for all the items in an array do this
      // first open the line of html.
      echo "<input type='button' onClick=Cycle(";
      //loop for all items in the array
      for ($i=0;$i<count($my_array);$i++) {
      echo	$my_array[$i].', ';
      }
      //now close the line html
      echo ")'value='Check Subtotal'>";
    
      // or if its from a database you'll have to set the results up
      // similarily to the last...
    
      // ie. here is a query
      $query = @mysql_query("SELECT items FROM myTable");
      $numRows = @mysql_num_rows($query);
    
    echo "<input type='button' onClick=Cycle(";
    // loop for db results
    for($i=0;$i<$numRows;$i++) {
    $row = @mysql_fetch_array($query);
    echo $row->items;
    }
    
    echo  ")'value='Check Subtotal'>";
    
      ?>
    

    Hope this makes sense.
    R

      Write a Reply...