php.de

Zurück   php.de > Webentwicklung > HTML, Usability und Barrierefreiheit

HTML, Usability und Barrierefreiheit Themen rund um Textauszeichnung, Formatierung, Barrierefreiheit und Usability.

Antwort
 
LinkBack Themen-Optionen Thema bewerten
Alt 18.10.2005, 13:20  
Gast
 
Beiträge: n/a
Standard [Erledigt] dynamisches Pulldown

Hallo zusammen!

Eins gleich vorweg: ich hab diese Frage schon in Nebenforum gestellt, aber da wollte / konnte mir keiner antworten, also versuch ich's hier (und hoffe dass ich hier auch eine Lösung auf mein Problem finde).

Ich möchte ein dynamisches Pulldown für mein Formular machen.
Man wählt zuerst den Monat, dann wird (via javascript) festgelegt, wieviele Tage zur Verfügung stehen.

zB 01 (Jänner) = 31, 02 (Februar) = 28

Mein Code ist folgender:
PHP-Code:
<?
// Pulldown - Monate

$monat "12";

?>
<form name="geburtstag" action="xxx.php" >
<?
echo "MONATE ";
echo 
"<select name='month_a' onchange='dynam_tage()'>";
for(
$i 1$i <= $monat$i++)
{
   
$tagesliste .= sprintf("<option value=\"%02d\">%02d</option>"$i$i);
   
printf("<option value=\"%02d\">%02d</option>"$i$i);
}
echo 
"</select>";

// dynamisches Pulldown - Tage

echo "dynamische TAGE ";
echo 
"<select>";
for(
$i 1$i <= $monat['month_a']; $i++)
{
   
$tagesliste .= sprintf("<option value=\"%02d\">%02d</option>"$i$i);
   
printf("<option value=\"%02d\">%02d</option>"$i$i);
}
echo 
"</select>";

echo 
"


"
;
echo 
$mon_array['01'];
echo 
"


"
;
?>
</form>
<?
?>
die javascript-Funktion sieht so aus:
Code:
<script type="text/javascript">
   function dynam_tage()
   {
      var monat = document.geburtstag.month_a.value;
      <?= $month_a ?> = monat;
   }
</script>
Tja, so wie ich's derzeit versuche geht's schonmal nicht...
Ich kann nämlich keine php-Variablen mit javascript füllen...

--> Ich brauche also eine javascriptfunktion die das ganze dynamisch macht
--> weiß jemand wie die aussehen muss?

Vielen Dank im Vorraus für jede Antwort!
  Mit Zitat antworten
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 18.10.2005, 19:41  
Gast
 
Beiträge: n/a
Standard

versuchs mal damit:
Code:
<html>
  <head>
    <script language="JavaScript">
      function get_days(opts_m, opts_d) {
        for (i = 0; i < 12; i++)
          if (opts_m[i].selected) {
            if (i == 1)
              var nod = 28;
            else if ((i < 6 && i % 2) || (i > 7 && i % 2 == 0))
              var nod = 30;
            else
              var nod = 31;  
            opts_d.length = nod;
            for (id = 0; id < nod; id++) {
              opts_d[id].text = id + 1;
              opts_d[id].value = id + 1;
            }
            break;
          }
      }
    </script>
  </head>

  <body onLoad="get_days(document.forms[0].elements[0].options, document.forms[0].elements[1].options)">
    <form>
      <select onChange="get_days(document.forms[0].elements[0].options, document.forms[0].elements[1].options)">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
      </select>
      <select>
        
      </select>
    </form>
  </body>
</html>
zweites select-element bitte nicht entfernen!

/edit: das erste selectfeld kannst du natürlich weiterhin mit php erzeugen!
  Mit Zitat antworten
Alt 19.10.2005, 09:06  
Gast
 
Beiträge: n/a
Standard

Hm, klingt ganz gut, danke!

Hab's aber gestern Abend dann noch alleine geschafft!

Wie finded ihr meine Lösung:
Code:
<script type="text/javascript">
	function dynam_tage_A()
	{
		var array_monate = new Array;
		array_monate["01"] = 31;	array_monate["02"] = 28;	array_monate["03"] = 31;
		array_monate["04"] = 30;	array_monate["05"] = 31;	array_monate["06"] = 30;
		array_monate["07"] = 31;	array_monate["08"] = 31;	array_monate["09"] = 30;
		array_monate["10"] = 31;	array_monate["11"] = 30;	array_monate["12"] = 31;

		var aktuell = document.geburtstag.month_a.value;
		aktuell = array_monate[aktuell];
		var i = 0;
		var tagesliste = 0;
		for(i = 0; i <= aktuell; i++)
		{
			if(i+1 < 10)
			{
				tagesliste = new Option("0"+(i+1));
			}
			else
			{
				tagesliste = new Option(i+1);
			}
			document.geburtstag.day_a.options[i] = tagesliste;
		}
		document.geburtstag.day_a.options.length = aktuell;
	}

	function dynam_tage_E()
	{
		var array_monate = new Array;
		array_monate["01"] = 31;	array_monate["02"] = 28;	array_monate["03"] = 31;
		array_monate["04"] = 30;	array_monate["05"] = 31;	array_monate["06"] = 30;
		array_monate["07"] = 31;	array_monate["08"] = 31;	array_monate["09"] = 30;
		array_monate["10"] = 31;	array_monate["11"] = 30;	array_monate["12"] = 31;

		var aktuell = document.geburtstag.month_e.value;
		aktuell = array_monate[aktuell];
		var i = 0;
		var tagesliste = 0;
		for(i = 0; i <= aktuell; i++)
		{
			if(i+1 < 10)
			{
				tagesliste = new Option("0"+(i+1));
			}
			else
			{
				tagesliste = new Option(i+1);
			}
			document.geburtstag.day_e.options[i] = tagesliste;
		}
		document.geburtstag.day_e.options.length = aktuell;
	}
</script>
  Mit Zitat antworten
Antwort


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
pulldown bar mit mysql abfrage konstinator1 Datenbanken 3 21.06.2008 23:55
Dynamisches Userprofil auf OOP-Basis PHP Tipps 2006 20 02.11.2006 21:05
[Erledigt] Dynamisches Dropdown HTML, Usability und Barrierefreiheit 3 06.03.2006 13:12
[Erledigt] dynamisches dropdown menü PHP Tipps 2006 3 11.01.2006 15:15
dynamisches Pulldown PHP Tipps 2005-2 1 18.10.2005 13:02
dynamisches Pulldown PHP Tipps 2005-2 13 12.10.2005 15:42
Werte aus DB in Auswahlfelder bzw. Pulldown Menus PHP Tipps 2005-2 7 11.10.2005 16:31
Dynamisches Formular dragon1402 PHP Tipps 2005-2 7 21.07.2005 12:01
Dynamisches Menü mit Icons PHP Tipps 2005 2 18.04.2005 16:03
Dynamisches Menu PHP Tipps 2005 11 22.03.2005 20:36
[Erledigt] Dynamisches Menü erweitern?? PHP Tipps 2005 1 19.03.2005 14:41
Pulldown kampfnickel PHP Tipps 2005 18 14.03.2005 14:03
Pulldown mit include CityHubter PHP Tipps 2005 2 08.02.2005 15:25
Dynamisches Menü mit untermenü PHP Tipps 2005 3 03.02.2005 18:52
pulldown funktioniert nicht bei firefox und opera HTML, Usability und Barrierefreiheit 7 30.10.2004 12:52

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
php tagesliste, pulldown geburtstag, pulldown php javascript, dynamisches pulldown, dynamischen menüs via js, dynamische pulldown

Alle Zeitangaben in WEZ +2. Es ist jetzt 01:43 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.