![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
21/11/2002, 01:41
|
![Avatar de epplestun](http://static.forosdelweb.com/customavatars/avatar5456_1.gif) | | | Fecha de Ingreso: octubre-2001
Mensajes: 1.621
Antigüedad: 23 años, 3 meses Puntos: 5 | |
Bueno, yo hice lo que creo que necesitas con JS, aki te dejo el codigo que tengo:
Código:
<SCRIPT language="JavaScript" type="text/javascript">
var kirolakArray = new Array("('','',true,true)",
"('Entrenamenduak')",
"('Deialdiak')",
"('Emaitzak')");
var txatxarroArray = new Array("('','',true,true)",
"('Urteko egitaraua')",
"('Deialdiak')");
var kulturalakArray = new Array("('','',true,true)",
"('Irteerak egitaraua')",
"('Egonaldiak egitaraua')",
"('Extraeskolarrak')");
var osagarriakArray = new Array("('','',true,true)",
"('Tandacui')",
"('Proyde-Proega')",
"('Antzerki ikustaldiak')",
"('S.Mitxelena saria')");
var bereziakArray = new Array("('','',true,true)",
"('Egonaldi irekiak')");
function populateCountry(inForm,selected) {
var selectedArray = eval(selected + "Array");
while (selectedArray.length < inForm.country.options.length) {
inForm.country.options[(inForm.country.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("inForm.country.options[i]=" + "new Option" + selectedArray[i]);
}
if (inForm.region.options[0].value == '') {
inForm.region.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}
function populateUSstate(inForm,selected) {
if (selected == 'USA') {
for (var i=0; i < stateArray.length; i++) {
eval("inForm.country.options[i]=" + "new Option" + stateArray[i]);
}
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0)
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0)
}
}
}
}
else {
}
if (selected == 'Otros') {
newCountry = "";
while (newCountry == ""){
newCountry=prompt ("Por favor, entre el nombre de su pais.", "");
}
if (newCountry != null) {
inForm.country.options[(inForm.country.options.length-1)]=new Option(newCountry,newCountry,true,true);
inForm.country.options[inForm.country.options.length]=new Option('Other, not listed','Other');
}
}
if(inForm.country.options[0].text == 'Select country') {
inForm.country.options[0]= null;
}
}
// End -->
</script>
<form name="hola">
<select class="FORMULARIO" name="region" onChange="populateCountry(document.hola,document.hola.region.options[document.hola.region.selectedIndex].value)">
<option selected value=''>Aukeratu bat</option>
<option value='kirolak'>Kirolak</option>
<option value='txatxarro'>Txatxarro</option>
<option value='kulturalak'>Kulturalak</option>
<option value='osagarriak'>Osagarriak</option>
<option value='bereziak'>Bereziak</option>
</select>
<select name="country" onChange="populateUSstate(document.hola,document.hola.country.options[document.hola.country.selectedIndex].text)">
<option value=''><--------------------</option>
</form>
Luego para insertar esos campos en la base de datos: Código PHP: <?php
include('../configuracion.inc');
$enlace = mysql_connect($host, $usuario, $password);
mysql_select_db($base_de_datos,$enlace);
$fecha = time() ;
$sql = "INSERT INTO ekintzak (tipo, seccion) ";
$sql .= "VALUES ('$region', '$country')";
$result = mysql_query($sql);
mysq_free_result($result);
mysq_close($enlace);
header("location: admin.php");
?> Espero que te sirva :P
__________________ Usuario registrado de Linux #288725 |