Re: [jQuery] Update div content after dynamic select creation

2010-02-03 Thread Nathan Klatt
On Wed, Feb 3, 2010 at 7:12 AM, Shinnuz  wrote:
> Database works, but if you see div#result doesn't update with "prova3"...
> why? where i'm wrong?

I do believe your problem is you're creating the nation select AFTER
you've set the handler for the select. Move your declaration of
$('#sel_nazioni').change(function() into $.post("selection.php",
{id_cont:cont}, function(data){, a la:

$(document).ready(function() {
   $('#sel_continenti').change(function(){
   var cont = $('#sel_continenti').attr('value');
   $.post("selection.php", {id_cont:cont}, function(data){
   $("#sel_nazioni").empty();
   //$("div#result").empty();
   $("div#nazioni").empty();
   $("div#result").append("prova2");
   //$("div#result").append(document.createTextNode("prova"));
   $("#sel_nazioni").prepend(data);
   $("div#nazioni").prepend(data);
   $('#sel_nazioni').change(function(){
   var id_naz = $('#sel_nazioni').attr('value');
   $.post("result.php", {id:id_naz}, function(data){
   $("div#result").empty();
   $("div#result").append("prova3");
   //$("div#result").prepend(data);
   });
   });
   });
   });
});

Nathan


[jQuery] Update div content after dynamic select creation

2010-02-03 Thread Shinnuz

I'm trying to create a page where onchange of first select it appears a
second one (which values, readen from a database, depend on previous choise)
and on choise of second select results are show in a div.

Here some images:

Start:

http://img269.imageshack.us/i/senzanomejg.png/
http://img269.imageshack.us/i/senzanomejg.png/ 

On first select choise:

http://img534.imageshack.us/i/senzanome2.png/
http://img534.imageshack.us/i/senzanome2.png/ 

On second select choise:

http://img269.imageshack.us/i/senzanome3y.png/
http://img269.imageshack.us/i/senzanome3y.png/ 

Here's the code:

index.php


http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>





$(document).ready(function() {

$('#sel_continenti').change(function(){
var cont = $('#sel_continenti').attr('value');

$.post("selection.php", {id_cont:cont}, function(data){
$("#sel_nazioni").empty();
//$("div#result").empty();
$("div#nazioni").empty();
$("div#result").append("prova2
"); //$("div#result").append(document.createTextNode("prova")); $("#sel_nazioni").prepend(data); $("div#nazioni").prepend(data); }); }); $('#sel_nazioni').change(function(){ var id_naz = $('#sel_nazioni').attr('value'); $.post("result.php", {id:id_naz}, function(data){ $("div#result").empty(); $("div#result").append("prova3
"); //$("div#result").prepend(data); }); }); }); ShowContinenti(); ?> prova1 File option.class.php DbConnectAndSelect(); } protected function DbConnectAndSelect() { //include_once "db_config.php"; //$this->conn = mysql_connect($db_host,$username,$password); $this->conn = pg_connect("host= port= user= password= dbname="); //mysql_select_db($db_name, $this->conn); return TRUE; } public function ShowContinenti() { echo 'Seleziona un continente:'; echo 'Scegli...'; $sql = "SELECT * FROM continenti"; //$res = mysql_query($sql,$this->conn); $res = pg_query($this->conn,$sql); while($row = pg_fetch_row($res)) { echo '' . $row[1] . ''; } echo ''; } /*public function ShowNazioni() { if($_POST['id_cont'] == "no") { die; } //echo 'Seleziona una nazione:'; //echo ''; $id_cont = $_POST['id_cont']; $sql = "SELECT * FROM nazioni WHERE id_cont=$id_cont"; $res = pg_query($this->conn,$sql); //echo'Scegli...'; while($row = pg_fetch_row($res)) { echo '' . $row[2] . ''; } //echo ''; }*/ public function ShowNazioni() { if($_POST['id_cont'] == "no") { die; } echo 'Seleziona una nazione:'; echo ''; $id_cont = $_POST['id_cont']; $sql = "SELECT * FROM nazioni WHERE id_cont=$id_cont"; $res = pg_query($this->conn,$sql); echo'Scegli...'; while($row = pg_fetch_row($res)) { echo '' . $row[2] . ''; } echo ''; } public function ShowResult() { echo "dentro shoresult()"; if($_POST['id'] == "no") { echo "post id=no"; die; } echo 'Hai scelto la nazione: '; $id = $_POST['id']; $sql = "SELECT * FROM nazioni WHERE id=$id"; $res = pg_query($this->conn,$sql); $row = pg_fetch_row($res); echo 'id: '.$row[0].' id_cont: '.$row[1].' nazione: '.$row[2]; } } ?> File selection.php ShowNazioni(); ?> File result.php ShowResult(); ?> Database works, but if you see div#result doesn't update with "prova3"... why? where i'm wrong? -- View this message in context: http://old.nabble.com/Update-div-content-after-dynamic-select-creation-tp27435815s27240p27435815.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.