Page 1 of 1

incorporating JS in dynamic php?

Posted: Fri Feb 22, 2008 10:19 am
by PhpDog
I'm creating a dynamic html select list with:

Code: Select all

 
// --- build default list ----------
$select_list  = "<select name='type' id='type'>";
 
   for($x = 0; $x < count($select); $x++)
    {
      if($x == 0)
       {
         $select_list .= "<option value='$select[$x]' selected>$select[$x]</option>";
       
       } else {
         
         $select_list .= "<option value='$select[$x]'>$select[$x]</option>";         
       }
    }
    
    $select_list .= "</select>";
 
However, I wish to incorporate a JS change event along the lines of: onChange="document.location.href='1.php'";

But I'm not sure how to incorporate this into my php. Any pointers would be much appreciated.

Re: incorporating JS in dynamic php?

Posted: Fri Feb 22, 2008 11:33 am
by Jonah Bron

Code: Select all

$select_list = '<select name="type" id="type" onchange="window.location=\'1.php\';">';

Re: incorporating JS in dynamic php?

Posted: Fri Feb 22, 2008 11:40 am
by RobertGonzalez
For the record, you don't integrate it into your PHP you integrate it into your markup. Like the youngster posted. :wink: