Seite 1 von 1

Dropdown mit js

Verfasst: Fr 20. Mär 2009, 13:21
von chpulat
Ich würde gerne ein Dropdown mit den Artikeln aus einer Kategorie und als Value den Links zu den Seiten (die noch nicht ganz funzen muss mir den urlbuilder noch anschauen aber das ist egal..)

bei "onchange" soll das Dropdown auf den ensprechend angeklickten artikel wechseln Artikel wechseln, aber es will einfach nicht.

Sieht jmd den Fehler?

im "output" vom Modul habe ich:

Code: Alles auswählen

 echo '<form name="select1"><select name="select" onchange="Javascript:if(this.options.value != \'0\'){location=this.options.value;}">';
 echo '<option selected value="0">Bitte wählen sie ein Produkt</option>';
  while ($db->next_record())
  {
      echo '<option value="http://www.domain.de/neu/Kategorie/index-a-'.$db->f("idart").'.html">'.$db->f("title").'</option><br>'."\n";
  }
  echo '</select></form>'
rauskommen tut dabei:

Code: Alles auswählen

<form name="select1"><select name="select" onchange="Javascript:if(this.options.value != '0'){location=this.options.value;}"><option selected value="0">Bitte wählen sie ein Produkt</option><option value="http://www.domain.de/neu/KATEGORIE/index-a-3.html">KATEGORIE</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-4.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-5.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-6.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-7.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-8.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-9.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-10.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-11.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-12.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-13.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-14.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-15.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-16.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-17.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-18.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-19.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-20.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-21.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-22.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-23.html">TITEL</option><br>
<option value="http://www.domain.de/neu/KATEGORIE/index-a-24.html">TITEL</option><br>
</select></form>
Wobei die Links und Titel alle richtig sind. also es liegt blos an dem blöden Javascript...

Vielen Dank für eure Mühe und schönes Wochenende

Re: Dropdown mit js

Verfasst: Fr 20. Mär 2009, 13:28
von MichFress
Nimm statt

Code: Alles auswählen

location=this.options.value

Code: Alles auswählen

location.href=this.options.value
href ist eine Eigenschaft des Objektes location.

Re: Dropdown mit js

Verfasst: Di 31. Mär 2009, 14:48
von chpulat
Hallo. Hab mein Modul jetzt ne ecke weiter entwickelt mit folgendem Code:
Input:

Code: Alles auswählen

?>
<table>
  <tr>
    <td><?php echo mi18n("Dropdown nutzen?");?></td>
    <td><input type="text" name="<?php echo "CMS_VAR[0]"; ?>" value="<?php echo "CMS_VALUE[0]"; ?>"></td>
  </tr>
  <tr>
    <td colspan=2>Dropdown nutzen: "NUTZEN" eintragen</td>
  </tr>
   <tr>
    <td colspan=2>Dropdown nicht nutzen Feld leer lassen</td>
  </tr>
    <tr>
    <td><?php echo mi18n("SprachID?");?></td>
    <td><input type="text" name="<?php echo "CMS_VAR[2]"; ?>" value="<?php echo "CMS_VALUE[2]"; ?>"></td>
  </tr>
  <tr>
    <td colspan=2>Wenn keine Sprachselektion gewünsch einfach leer lassen.</td>
  </tr>
</table>
<?php
Output

Code: Alles auswählen

<?php  
  $activ= "CMS_VALUE[0]";
  $spr="CMS_VALUE[1]";

  if (!($activ=="")){
  
if (ISSET($spr) && !($spr=""))
  {
      $imba="SELECT `con_art_lang`.`online`, `con_art_lang`.`artsort`, `con_art_lang`.`idart`, `con_art_lang`.`title`, `con_cat_art`.`idcat`, `con_cat_art`.`idart` FROM con_art_lang, con_cat_art WHERE ((`con_art_lang`.`online` =1)AND(`con_cat_art`.`idcat` =5) AND (`con_cat_art`.`idart` =`con_art_lang`.`idart`) AND (`con_art_lang`.`idlang`=".$spr.")) ORDER BY `con_art_lang`.`artsort` ASC;";
      echo $imba;
      echo $spr;
      echo $activ;
  } else {
  $imba="SELECT `con_art_lang`.`online`, `con_art_lang`.`artsort`, `con_art_lang`.`idart`, `con_art_lang`.`title`, `con_cat_art`.`idcat`, `con_cat_art`.`idart` FROM con_art_lang, con_cat_art WHERE ((`con_art_lang`.`online` =1)AND(`con_cat_art`.`idcat` =5) AND (`con_cat_art`.`idart` =`con_art_lang`.`idart`)) ORDER BY `con_art_lang`.`artsort` ASC";
  }
  $db->query($imba);
  $link="";
  echo '<form name="select1">Produktauswahl:    <select name="select" onchange="if (this.options[this.selectedIndex].value.length!=0) location=this.options[this.selectedIndex].value">';
  echo '<option selected value="0">Bitte wählen sie ein Produkt</option>';
  while ($db->next_record()) 
/*das ist mein url builder*/
       {  
         $link="http://www.domain.de/neu/Kategorie/";
         If (!($db->f("title")=="Kategorie34")) {$link .= str_replace(' ', '',$db->f("title"))."/";}
         else {$link .= "UEbersicht/";}         
         $link .= "index-b-".$db->f("idcat")."-".$db->f("idart").".html";
         echo '<option value='.$link.'>'.$db->f("title").'</option>'."\n";       
       }
  echo '</select></form>';
  }
?>
Das funktioniert auch soweit ganz gut. ist grade ne DEV-Version, da die QL-Statements mit ausgegeben werden ggf. einfach löschen.

Mein Problem ist nur, dass er im Input die erste Variable(CMS_VALUE[0]) wunderbar erkennt, aber im Output die CMS_VALUE[1] nicht. Aber sie ist da (isset =true). Im Input speichert sich der Wert, wenn ich ihn eingebe. Nur im Output komme ich net dran, einfach ein leerer String. :( :( help

Die SQL Abfrage muss ich noch optimieren, aber die läuft! :-D

Gruß Chris