Salve, come si fa a fare un form dinamico nel quale al variare del contenuto di un campo text (valori da 1 a 10) un menù list si aggiorna con campi option diversi?
Grazie.
Salve, come si fa a fare un form dinamico nel quale al variare del contenuto di un campo text (valori da 1 a 10) un menù list si aggiorna con campi option diversi?
Grazie.
forse questo è piu da javascript...
in php nn credo si possa fare nella stessa pagina.. a meno che nn si usa frame..
solo con php non lo puoi fare, se vuoi una cosina dinamica e bella utilizza AJAX, ci sono dei progetti molto interessanti e ben fatti e sopratutto semplici da capire, come SAJAX oppure se hai voglia ti fai tu una cosa con Protype e il tuo codice PHP
Zend Framework Italian Forum
http://www.zfforum.it
Ciao.
Senza scomodare Ajax puoi recuperare
i valori di una query e metterli in un array js
poi ad esempio puoi utilizzare questo codice
(come tutte le cose si può migliorare)
Spero che ti possa aiutare.Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>MyInput</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function createInputText()
{
var myinput = document.createElement("input");
myinput.setAttribute("id", "myinput");
myinput.setAttribute("type", "text");
document.getElementById("frm").appendChild(myinput);
init();
}
function createSelect(myarray)
{
if(test = document.getElementById("myselect"))
{
document.getElementById("frm").removeChild(test);
}
var myinput = document.getElementById("myinput");
var index = myinput.value;
if(index=='' || index==0 || index > 10)
{
init();
return;
}
var myselect = document.createElement("select");
myselect.setAttribute("id", "myselect");
document.getElementById("frm").appendChild(myselect);
for (i=0; i < myarray[index].length; i++)
{
document.getElementById("myselect").options[i] = new Option(myarray[index][i],i);
}
}
function init()
{
var myselect = document.createElement("select");
myselect.setAttribute("id", "myselect");
document.getElementById("frm").appendChild(myselect);
document.getElementById("myselect").options[0] = new Option("------","0");
}
window.onload = function()
{
// QUESTO LO PUOI FARE CON PHP
var myarray = new Array();
myarray[1] = new Array("uno1","due1","tre1");
myarray[2] = new Array("uno2","due2","tre2");
myarray[3] = new Array("uno3","due3","tre3");
//etc
myarray[10] = new Array("uno10","due10","tre10");
createInputText();
var myinput = document.getElementById("myinput");
myinput.onkeyup = function()
{
createSelect(myarray);
}
}
</script>
</head>
<body>
<form id="frm" action="mypage.php" method="post" name="frm">
</form>
</body>
</html>
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Ciao Ragazzi...dire che Whisher mi ha dato la soluzione migliore...complimenti davvero!
Senti una cosa...volendo stampare invece di un menù list una serie di tre, per esempio, radio button o checklist, invece?
Si può fare?
E un caffè![]()
Penso di sì basta adattare lo script.
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Oh Whisher, scusa se ti rompo...il problema è che i check-in sono variabili...non so proprio come adattare lo script, magari può essere utile visto che sul sito non c'è nulla in merito...
Tipo:
se il campo text è uno, allora stampa due check-in, se tre stampane tre
Il vantaggio è che sono preimpostati...
Please...![]()
Oh gio-mx quanto rompi
Here the masterpiece is
Occhio che c'è il copyright![]()
BugsCodice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>MyTextBox © whisher :)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
var count = 0;
function createInputText()
{
var myinput = document.createElement("input");
myinput.setAttribute("id", "myinput");
myinput.setAttribute("type", "text");
document.getElementById("frm").appendChild(myinput);
}
function createTextBox()
{
var count = getCheckBox();
if(count)
{
for(j = 0; j < count; j++)
{
document.getElementById("frm").removeChild(document.getElementById("mycheckbox" + j));
}
}
var myinput = document.getElementById("myinput");
var value = myinput.value;
for(i = 0; i < value; i++)
{
var mytextBox = document.createElement("input");
mytextBox.setAttribute("type", "checkbox");
mytextBox.setAttribute("id", "mycheckbox" + i);
mytextBox.setAttribute("value", i);
document.getElementById("frm").appendChild(mytextBox);
}
}
function getCheckBox()
{
var arrayinput = document.getElementsByTagName("input");
var string = "";
var myTextBox = new Array();
if(count!=0)
{
count = 0;
}
for(i = 0; i < arrayinput.length; i++)
{
string = arrayinput[i].getAttribute("type");
if(string.indexOf("checkbox")!=-1)
{
count++;
}
}
return count;
}
window.onload = function()
{
createInputText();
var myinput = document.getElementById("myinput");
myinput.onblur = function()
{
createTextBox();
}
}
</script>
</head>
<body>
<form id="frm" action="mypage.php" method="post" name="frm">
</form>
</body>
</html>
Not bloody likely
Scherzi a parte se la usi davvero dacci
una profonda controllata.
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Grazie Wisher, sei un fenomeno...![]()
P.S. Potresti metterequestoscript negli script della parte javascript...