Languages: PHP,JQuery,MySQL
The question is "simple", I have a triple dependency with php and jquerys, the code works great, for inserting new information, but now I would like to make an update, so I need to load the current information first and I don't figure it out how to, I add some parts of the code, if any more parts needed ask me before voting me down please.
Code is something like this:
<tr>
<td class="main"><?php echo ENTRY_COUNTRY; ?></td>
<td class="main">
<select id="country" name="country">
<option value="0">Select One...</option>
</select>
</td>
</tr>
<tr>
<td class="main"><?php echo ENTRY_STATE; ?></td>
<td class="main">
<select id="state" name="state">
<option value="0">Select One...</option>
</select>
</td>
</tr>
<tr>
<td class="main"><?php echo ENTRY_CITY; ?></td>
<td class="main">
<select id="city" name="city">
<option value="0">Select One...</option>
</select>
</td>
</tr>
The three are loaded from a db in mysql, by actions like:
<script type="text/javascript">
$(document).ready(function(){
cargar_paises();
$("#country").change(function(){dependencia_estado();});
$("#state").change(function(){dependencia_ciudad();});
$("#city").change(function(){dependencia_zip();});
$("#state").attr("disabled",true);
$("#city").attr("disabled",true);
});
function cargar_paises()
{
$.get("scripts/cargar-paises.php", function(resultado){
if(resultado == false)
{
alert("Error");
}
else
{
$('#country').append(resultado);
}
});
}
function dependencia_estado()
{
var code = $("#country").val();
$.get("scripts/dependencia-estado.php", { code: code },
function(resultado)
{
if(resultado == false)
{
alert("No se encontraron provincias para ese pais");
$("#state").attr("disabled",true);
document.getElementById("state").options.length=1;
}
else
{
$("#state").attr("disabled",false);
document.getElementById("state").options.length=1;
$('#state').append(resultado);
}
}
);
}
function dependencia_ciudad()
{
var code = $("#state").val();
$.get("scripts/dependencia-ciudades.php?", { code: code }, function(resultado){
if(resultado == false)
{
alert("Error");
}
else
{
$("#city").attr("disabled",false);
document.getElementById("city").options.length=1;
$('#city').append(resultado);
}
});
..... Thanks for everything ;) sorry for the english.