combo box problem

amira - June 20, 2009 - 18:47

i want when value change on my combo box it display the corresponding web site in new tab or window

<?
function  managelinks_block($op = 'list', $delta = 0, $edit = array())

if ($op == "list")
{
    // Generate listing of blocks from this module, for the admin/block page
    $block = array();
    $block[0]["info"] = t('Select a link');
    return $block;
  }
else if ($op == 'view')
{
   $query = "SELECT title FROM " .
     "{managelinks }";

  $queryResult =  db_query($query);


  $block_content = ''; 
  $cbo ='';

  while ($links = db_fetch_object($queryResult))
  {  
   $option[] = $links ;
  }
 
  $cbo .= '<select onchange="address(this)"  name="select" id="select">';
 
  foreach( $option as $key => $val)
  {
  $cbo .="<option>".$val->title."</option>";
  }
  $cbo .= '</select>';
 
 
  $block_content .= $cbo;
  $block_content .="<input type='submit' value='Go'>";
 
  ?>
  <script>
    function address(obj)
{
var dropdownIndex = document.getElementById('select').selectedIndex;
var dropdownValue = document.getElementById('select')[dropdownIndex].text;
//alert(dropdownValue);
<?
$query = "SELECT url FROM " .
        "{managelinks } where title='dropdownValue'";

$queryResult =  db_query($query);

while ($arr = db_fetch_object($queryResult))
{  
?>
alert("$arr[0]");
document.forms[0].cat_name.value= obj.options[obj.selectedIndex].text;
<?
}
?>
</script>
  <?
 
if ($block_content == '') {   
    /* No content from a week ago.  If we return nothing, the block  
     * doesn't show, which is what we want.
     */
    return;
  }

  // set up the block 
  $block = array();
  $block['subject'] = 'Manage Links'; 
  $block['content'] = $block_content;
  return $block;
}

 


} // end function

?>

but it doesont work well,so any help

thanks for advance

Have a look at jQuery

JoepH - June 20, 2009 - 19:08

which is in core. Should not be difficult to get this done with jQuery.

-----------------------------------------
Joep
CompuBase, Drupal, websites and webdesign

-----------------------------------------
Joep
CompuBase, Dutch Drupal full service agency

srry ,but what and how can i

amira - June 20, 2009 - 19:21

srry ,but what and how can i use jQurey...?

Try Google or goto Jquery and

JoepH - June 21, 2009 - 12:38

Try Google or goto Jquery and dig into it.
Really, jquery is a blessing if you want to write javascipt.

Good luck.

-----------------------------------------
Joep
CompuBase, Dutch Drupal full service agency

 
 

Drupal is a registered trademark of Dries Buytaert.