incorporating JS in dynamic php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

incorporating JS in dynamic php?

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: incorporating JS in dynamic php?

Post by Jonah Bron »

Code: Select all

$select_list = '<select name="type" id="type" onchange="window.location=\'1.php\';">';
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: incorporating JS in dynamic php?

Post by RobertGonzalez »

For the record, you don't integrate it into your PHP you integrate it into your markup. Like the youngster posted. :wink:
Post Reply