Welcome, Guest
Username: Password: Remember me

TOPIC: [SOLVED] Dynamic Select - Please help

[SOLVED] Dynamic Select - Please help 11 Sep 2012 17:37 #3523

  • zamora322
  • zamora322's Avatar
  • Offline
  • New Member
  • Posts: 6
  • Karma: 0
EDIT:

I get it!! :woohoo:

Thanks!





Hi :blush: ,

I have a 3 tables (country, state, city and myTable) and I'm trying to show on "myTable" the correct city and state depending (filtering) of a country selected.

As sample please see the following data from my tables:

country
- USA
- Canada
- Mexico

state
- Nueva York
- Hidalgo
- Sonora

city
- Nueva York
- Bronx
- Jalisco

I want show in the form the current state and city of each country selected. :blink:

If I select USA (as country) I need to see Nueva York (on state) and when I select Nueva York I need see Bronx and Nueva York (as city).

Sorry for my complex or incomplete explanation...

I'm working with a JavaScript code (of a friend):
function obtiene_http_request()
{
var req = false;
try
  {
    req = new XMLHttpRequest(); /* p.e. Firefox */
  }
catch(err1)
  {
  try
    {
     req = new ActiveXObject("Msxml2.XMLHTTP");
  /* algunas versiones IE */
    }
  catch(err2)
    {
    try
      {
       req = new ActiveXObject("Microsoft.XMLHTTP");
  /* algunas versiones IE */
      }
      catch(err3)
        {
         req = false;
        }
    }
  }
return req;
}
var miPeticion = obtiene_http_request();
//***************************************************************************************
function from(id,ide,url){
		var mi_aleatorio=parseInt(Math.random()*99999999);//para que no guarde la página en el caché...
		var vinculo=url+"?id="+id+"&rand="+mi_aleatorio;
		//alert(vinculo);
		miPeticion.open("GET",vinculo,true);//ponemos true para que la petición sea asincrónica
		miPeticion.onreadystatechange=miPeticion.onreadystatechange=function(){
               if (miPeticion.readyState==4)
               {
				   //alert(miPeticion.readyState);
                       if (miPeticion.status==200)
                       {
                                //alert(miPeticion.status);
                               //var http=miPeticion.responseXML;
                               var http=miPeticion.responseText;
                               document.getElementById(ide).innerHTML= http;

                       }
               }/*else
               {
			document.getElementById(ide).innerHTML="<img src='ima/loading.gif' title='cargando...' />";

                }*/
       }
       miPeticion.send(null);

}

I need implement this code in JDom or use JFactory::getDBO(); the best way. I hope you can help me. Thanks in advance. :)

In this moment i'm changing the following:
<?php echo JDom::_('html.form.input.ajax', array(
												'dataKey' => 'countryid',
												'dataObject' => $this->estadio,
												'ajaxContext' => 'soefutbol.paises.ajax.groupby25',
												'domClass' => "validate[required]",
												'required' => true,
												'validatorMsgInfo' => "SOEFUTBOL_VALIDATOR_COUNTRY_ERROR",
												'ajaxVars' => array('values' => array(
													$this->estadio->countryid
														))
												));
				?>

For this code:
<?php
    			$db	=& JFactory::getDBO();
				$query = "SELECT * FROM #__soefutbol_paises";
				$db->setQuery($query);
				$result = $db->loadObjectList();
        		
            ?>
            
			<select name="countryid" onchange="from(document.adminForm.countryid.value,'ciudad','components/com_soefutbol/requeridos/ciudad.php')" id="countryid" data-validation-engine="validate[required]" id="countryid" style="border-left:3px red solid;">
			<option value="">- País -</option>

				<?php
					foreach ($result as $row)
						{
				?>
							<option value="<?php echo $row->id;?>"><?php echo $row->country;?></option>
				<?php
						}
				?>

When I select the country the function is called: onchange="from(document.adminForm.countryid.value,'ciudad','components/com_soefutbol/requeridos/ciudad.php')"

And the ID form the DIV "ciudad" is changed by the contend of ciudad.php

But when I try to modify something i can't see the element saved in this case I only can see "- País -"...

Please help. :(
Last Edit: 03 Oct 2012 13:41 by admin.
The administrator has disabled public write access.
Time to create page: 0.126 seconds

Get Started