Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Moderatore di Macintosh e software L'avatar di olivs
    Registrato dal
    Jan 2001
    Messaggi
    8,906

    [javascript + php + MySQL] Select dinamiche

    Ho cercato sul forum ma ho trovato ottimi aiuti ma niente che coinvolgesse pure mysql...
    Dunque ho due tabelle:
    1. tipi -> id_tipo, tipo;
    2.sottotipi -> id_sottotipo, id_tipo, nome_sottotipo

    Ora devo fare due select, seleziona il tipo e seleziona il sottotipo.
    Gli option sono fatti cosi rispettivamente:
    <option value="$id_tipo"> e <option value="$id_sottotipo">
    Il problema è questo, come faccio a generare il secondo select dei sottotipi in base al tipo scelto ?

  2. #2
    Utente di HTML.it L'avatar di oronze
    Registrato dal
    Jun 2001
    Messaggi
    3,543
    Non ho molto tempo quindi adatta questo:
    codice:
    <HTML><HEAD>
    <TITLE>Untitled</TITLE>
    </HEAD>
    <BODY>
    <SCRIPT language=javascript>
    var iArrayMax = 7
    var aDropdown = new Array(iArrayMax)
    
    //as the page loads - first thing to do is to load the dropdown array
    var bOk = LoadArrays()
    
    function LoadArrays()
    {
    //this can be thought of as an object array, each element can be identified as a property of the array position
    // a very powerful structure for 'client side' data caching.
    Array[0] = new sElement('SO','Mac','Machintosh')
    Array[1] = new sElement('SO','lix','Linux')
    Array[2] = new sElement('SO','win','Windows')
    Array[3] = new sElement('SO','Alt','Altri')
    Array[4] = new sElement('MC','dw','Dreamwaver')
    Array[5] = new sElement('MC','fl','Flash')
    Array[6] = new sElement('MC','fh','Freehand')
    Array[7] = new sElement('MC','fw','Fireworks')
    
    
    return true
    }
    
    function sElement(sParentId,sValue,sDescription)
    {	
    	// elements that will be loaded into the array structure and persisted
    	// think of it as an object.
    	this.ParentId = sParentId
    	this.Id = sValue
    	this.Description = sDescription
    }
    
    function bCascadeDrop(oDDsource,oDDdest)
    {
    	//function to enable cascading dropdowns
    	//called as the parent dropdown changes.
    	var iX
    	var sText
    	var iY= 0
    	var sOptionId
    	var sOptionDesc
    	var iStartPos
    		
    	//find the value of the item currently selected		
    	sText = oDDsource.options[oDDsource.selectedIndex].value 
    	if (sText != '0')
    	{
    		//clear down the destination list box
    		oDDdest.options.length = 0                
    		
    		//loop through the elements that are in the array
    		// if they match the parent if then they should be displayed.
    		for (iX=0; iX<=iArrayMax; iX++) 
    		{		
    			if(sText == Array[iX].ParentId)
    			{
    			//grab the values out of the element (Netscape is not happy doing too many things in a function call!)
    			sOptionId = Array[iX].Id
    			sOptionDesc= Array[iX].Description
    			//alert(sOptionDesc)
    			
    			//write the element into the dripdown box.		
    			oDDdest.options[iY] = new Option (sOptionDesc,sOptionId)	
    			iY = iY +1		
    			}	
    		}	
    	}	
    }
    </SCRIPT>
    
    <FORM action=FrmNew>
    <TABLE>
      <TBODY>
      <TR>
        <TD>Categoria</TD>
        <TD><SELECT style="WIDTH: 150px" onchange="bCascadeDrop(this, document.forms[0].sRegion)" name=sCountry> 
            <OPTION value=0 selected>Categoria...</OPTION> <OPTION 
            value=SO>Sistema operativo</OPTION> <OPTION 
          value=MC>Macromedia</OPTION></SELECT> Sottocategoria <SELECT style="WIDTH: 150px" name=sRegion size="1"><OPTION value=0 selected>&lt;---------------------</OPTION> </SELECT> 
     </TD></TR>
      </TBODY></TABLE></FORM></BODY></HTML>
    Se proprio non riesci chiedi pure chiarimenti al sottoscritto che proverò a risolverti i problemi....

    No ai layout tabellari!

    Insulto libero: http://forum.html.it/forum/showthread.php?s=&postid=12524872#post12524872

  3. #3
    Moderatore di Macintosh e software L'avatar di olivs
    Registrato dal
    Jan 2001
    Messaggi
    8,906
    grazie molto gentile..

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2012
    Messaggi
    12
    scusa il disturbo
    avrei bisogno di creare un form con 3 menù a tendina con dentro regioni province e comuni e che si aggiornino automaticamente e i dati relativi li ho in un database in phpmyadmin in sql come posso fare non è che mi potresti da una mano con il codice ??

    grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.