Jump to content

Linked dynamic select list issue


thursgun

Recommended Posts

Hi,

 

I really really really need some help with this annoying issue (I've searched  in the web a lot because im too lazy at making post, but this is pissing me off  :-[ )

 

 

The following code show 3 "linked" select lists. "Proyecto", "Fase" and "Etapa". So I choose an item from proyecto, and the select box "Fase" shows the items associated to the item selected. Same with "Fase" and "Etapa".

 

When I select an item from Proyecto, the page reloads, and the selected item is being displayed on the select box of Proyecto. However, when I do the same with Fase, the item is not displayed and the message "-- Elija una fase --" appears instead. (this doesn't mean that the Etapa select doesn't work, because it does).

 

P.S: Im sorry if the code is not clear enough, but feel free to ask anything about it.

 

Heres the code:

(some words in spanish, but nothing serious)

<SCRIPT language=JavaScript>
function reload(form)
{
	var val_proyecto=form.proyecto.options[form.proyecto.options.selectedIndex].value;
	//var val_fase=form.fase.options[form.fase.options.selectedIndex].value;

	self.location='xxx.php?proyecto=' + val_proyecto;// + '& fase=' + val_fase ;
}

function reload2(form, val_proyecto)
{
	var val_fase=form.fase.options[form.fase.options.selectedIndex].value;
	var val_etapa=form.etapa.options[form.etapa.options.selectedIndex].value;
	self.location='xxx.php?proyecto=' + val_proyecto + '& fase=' + val_fase ;
}
</script>

<?php
$conn = pg_connect("host=localhost port=5432 password='' user=postgres dbname= DB ");
if (pg_ErrorMessage($conn))
{ 
	echo "<p><b>Ocurrio un error conectando a la base de datos: .</b></p>"; 
	exit;
}

$query_proyecto=pg_query("SELECT * FROM proyecto");

@$proyecto=$_GET['proyecto'];
@$fase=$_GET['fase'];

if(isset($proyecto) and strlen($proyecto) > 0)
{
	$query_fase=pg_query("SELECT * FROM fase WHERE id_proyecto=".$proyecto);
	if(isset($fase) and strlen($fase) > 0)
	{
		$query_etapa=pg_query("SELECT * FROM etapa WHERE id_fase=".$fase. " AND id_proyecto=".$proyecto);
	}
}


echo "<form method=post name=f1 action='dd-check.php'>";
	//lista de proyectos
	echo "<select name='proyecto' onchange=\"reload(this.form)\"><option value=''>-- Elija un proyecto --</option>";
		while($select_proyecto = pg_fetch_array($query_proyecto))
		{
			if($select_proyecto['id_proyecto']==@$proyecto)
			{
				echo "<option selected value='".$select_proyecto['id_proyecto']."'>".$select_proyecto['nombre_proyecto']."</option>";
			}
			else
			{
				echo "<option value='".$select_proyecto['id_proyecto']."'>".$select_proyecto['nombre_proyecto']."</option>";
			}
		}
	echo "</select>";

	//lista de fases
	echo "<select name='fase' onchange=\"reload2(this.form,".$proyecto.")\"><option value=''>-- Elija una fase --</option>";
		while($select_fase = pg_fetch_array($query_fase)) 
		{
			if($select_fase['id_fase']==@$fase)
			{
				echo "<option value='".$select_fase['id_fase']."'>".$select_fase['nombre_fase']."</option>";
			}
			else
			{
				echo "<option value='".$select_fase['id_fase']."'>".$select_fase['nombre_fase']."</option>";
			}
		}
	echo "</select>";

	//lista de etapas
	echo "<select name='etapa'><option value=''>-- Elija una etapa --</option>";
		while($select_etapa = pg_fetch_array($query_etapa)) 
		{
			echo "<option value='".$select_etapa['id_etapa']."'>".$select_etapa['nombre_etapa']."</option>";
		}
	echo "</select>";

	echo "<input type=submit value=Submit>";
echo "</form>";
?>

Link to comment
Share on other sites

Solved

 

Ok, if anyone, someday somewhere needs this info, the problem was that I missed the word "selected" here :

 

(no code tag so I can highlight the word  ;D)

 

 

//lista de fases

      echo "<select name='fase' onchange=\"reload2(this.form,".$proyecto.")\"><option value=''>-- Elija una fase --</option>";

        while($select_fase = pg_fetch_array($query_fase))

        {

            if($select_fase['id_fase']==@$fase)

            {

              echo "<option selected value='".$select_fase['id_fase']."'>".$select_fase['nombre_fase']."</option>";

            }

            else

            {

              echo "<option value='".$select_fase['id_fase']."'>".$select_fase['nombre_fase']."</option>";

            }

        }

      echo "</select>";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.