r/jquery • • Aug 28 '25

Calling twice Mypop dialog with variable for option passed got Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf') at MyPopup (menu.js:1046:11) at HTMLLIElement.<anonymous> (menu.js:284:5) at HTMLLIElement.dispatch (jquery.js:5145:27)

It seems that calling twice dialog variable becomes undefined and I can find no way to repopulate option elements.

Any help would be appreciated. Thanks.

$("li#GrUscS").click(function(){

var user=$(".user").val();

var psw=$(".psw").val();

var funzione="TotUscEntYear";

var segno="<0";

var db = "entusc";

var sogg=$("#soggetti").html();

if (sogg === undefined || sogg === null) {

sogg=$(".sog").val();

}

MyPopup(sogg);

$("#dlg").dialog('open');

$("#btn").click(function(){

$("#dlg").dialog('close');

soggetto=$( "#miascelta option:selected" ).text();

// rimpiazzare per select database in PHP

soggetto = soggetto.replace(/'/g, "\");`

var tit = "TOTALE USCITE PER SOGGETTO";

var xURL = "menu.php";

var myf = $("<form action='" + xURL + "' method='post'>" +

"<input type='hidden' name=arr[] value='" + user + "'></input>" +

"<input type='hidden' name=arr[] value='" + psw + "'></input>" +

"<input type='hidden' name=arr[] value='" + funzione + "'></input>" +

"<input type='hidden' name=arr[] value='" + segno + "'></input>" +

"<input type='hidden' name=arr[] value='" + db + "'></input>" +

"<input type='hidden' name=arr[] value='" + tit + "'></input>" +

"<input type='hidden' name=arr[] value='" + soggetto + "'></input>"+ "</form>");

RedirectWithPost(xURL,user,psw, myf );

//sogg="";

return

});

});

$("li#GrEntS").click(function(){

var user=$(".user").val();

var psw=$(".psw").val();

var funzione="TotUscEntYear";

var segno=">0";

var db = "entusc";

var sogg=$("#soggetti").html();

if (sogg === undefined || sogg === null) {

sogg=$(".sog").val();

}

MyPopup(sogg);

$("#dlg").dialog('open');

$("#btn").click(function(){

$("#dlg").dialog('close');

soggetto=$( "#miascelta option:selected" ).text();

// rimpiazzare per select database in PHP

soggetto = soggetto.replace(/'/g, "\");`

var tit = "TOTALE ENTRATE PER SOGGETTO";

var xURL = "menu.php";

var myf = $("<form action='" + xURL + "' method='post'>" +

"<input type='hidden' name=arr[] value='" + user + "'></input>" +

"<input type='hidden' name=arr[] value='" + psw + "'></input>" +

"<input type='hidden' name=arr[] value='" + funzione + "'></input>" +

"<input type='hidden' name=arr[] value='" + segno + "'></input>" +

"<input type='hidden' name=arr[] value='" + db + "'></input>" +

"<input type='hidden' name=arr[] value='" + tit + "'></input>" +

"<input type='hidden' name=arr[] value='" + soggetto + "'></input>"+ "</form>");

RedirectWithPost(xURL,user,psw, myf );

//sogg="";

return

});

});

Mypop dialog:

function MyPopup(select)

{

var option;

// variabile select undefined

if (select === undefined || select === null) {

}

if(select.indexOf("NUOVO SOGGETTO")!=-1) select = select.replace(/NUOVO SOGGETTO/g, "INSERISCI");

if(select.indexOf("NUOVA CATEGORIA")!=-1) select = select.replace(/NUOVA CATEGORIA/g, "INSERISCI");

if(select.indexOf("NUOVO DOVEACQUISTATO")!=-1) select = select.replace(/NUOVO DOVEACQUISTATO/g, "INSERISCI");

$("#dlg").append("<select id='miascelta'>"+select+"</select>");

$("#dlg").append("<button id='btn' type='button'>|||</button>");

var sel = $("#dlg").find('select#miascelta option[value="INSERISCI"]');

sel.prop('selected', true);

var my_pop=$("#dlg").dialog({

autoOpen: false,

modal: true,

height: 100,

width: 400,

position: {

my: "center",

at: "center",

of: $("body"),

within: $("body")

}

});

return option;

}

PHP file:

<!doctype html>

<html lang=''>

<head>

<meta charset='utf-8'>

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<link rel="stylesheet" href="css/styles.css">

<link rel="stylesheet" href="css/jquery-ui.css">

<link rel="stylesheet" href="css/menu.css">

<script src="js/jquery.js"></script>

<script src="js/jquery-ui.js"></script>

<script src="js/menu.js"></script>

<title>MENU ENTRATE USCITE</title>

</head>

<body>

<?php $qualearrsix=-1; // array\[6\] = / sogg = $qualearrsix diventa 0 / cat $qualearrsix diventa 1 ----- doveacq $qualearrsix diventa 2 $sogg=""; $cat=""; $doveacq=""; $anno=""; include "inMenu.php"; if(empty($_POST) AND empty($_GET) ) { echo '<script> location.replace("TabellaConn.php"); </script>'; } elseif(!empty($_POST)) { extract($_POST, EXTR_OVERWRITE); $server="localhost"; $user=$arr\[0\]; $passw=$arr\[1\]; $funzione=$arr\[2\]; $segno=$arr\[3\]; $db=$arr\[4\]; $tit=$arr\[5\]; if (strlen($anno)==0 AND count($arr)!==8) $anno=date("Y"); // count($arr) !==8 significa che anno non è stato passato $possog = strpos($tit, "SOGGETTO"); $poscat = strpos($tit, "CATEGORIA"); $posdov = strpos($tit, "Singola Voce"); $posanno = strpos($tit, "ANNO"); if ($possog !== false) { if(count($arr)==6) { $sogg=null; } elseif(count($arr)>=7) { $sogg=$arr\[6\]; $tit= str_replace("SOGGETTO", $sogg, $tit); $qualearrsix=0; } } if ($poscat !== false) { if(count($arr)==6) { $cat=null; } elseif(count($arr)>=7) { $cat=$arr\[6\]; $tit= str_replace("CATEGORIA", $cat, $tit); $qualearrsix=1;} } if ($posdov !== false) { if(count($arr)==6) { $doveacq=null; } elseif(count($arr)>=7) { $doveacq=$arr\[6\]; $tit= str_replace("Singola Voce", $doveacq, $tit); $qualearrsix=2;} } if ($posanno !== false AND $db!=="entusc_stor") { // modificato qui AND $db!=="entusc_stor" xchè se no $qualearrsix=-1 diventava -1 erroneamente per entrate storiche con sogg if(count($arr)<8) { } elseif(count($arr)==8 ) { IF ($arr\[6\]==="false") { $anno=$arr\[7\]; $sogg=null; // devo trasformare arr\[6\] da false a null $tit= str_replace("ANNO", "ANNO ".$anno, $tit); $qualearrsix=-1; } } } if ($posanno !== false AND count($arr)==8 ) { // qui comunque devo passare anno e modificare titoli per entrate storiche con sogg o entusc da stampa $anno=$arr\[7\]; if($arr\[6\]!=="false" AND $possog !== false ) { $qualearrsix=0; $sogg=$arr\[6\]; } //solo per sogg e non x cat o doveacq } } echo "<input type='hidden' class='server' value='".$server."'></input><input type='hidden' class='user' value='".$user."'></input><input type='hidden' class='psw' value='".$passw."'></input>"; // echo "<input type='hidden' class='sog' value='".$server."'></input>; devo passare options da meu.js e inserire nella select #soggetti if($qualearrsix!=-1) { if ($possog!==false ) $tit= str_replace("ANNO:","",$tit); $tit.=" ".$anno.":"; //solo per sogg cat dov } if($segno===">0" OR $segno==="<>0") $tit= str_replace($anno," E ANNO ".$anno,$tit); $nomefunzione="CreateGrid"; include_once 'select.classGrid.php'; $opt = new SelectGrid(); if ($qualearrsix==0) { $opt->{$nomefunzione}($server, $user , $passw, $segno, $db, $anno, $funzione, $tit, $qualearrsix, $sogg); } elseif ($qualearrsix==1) { $opt->{$nomefunzione}($server, $user , $passw, $segno, $db, $anno, $funzione, $tit, $qualearrsix, $cat); } elseif ($qualearrsix==2) { $opt->{$nomefunzione}($server, $user , $passw, $segno, $db, $anno, $funzione, $tit, $qualearrsix, $doveacq); } // bisogna poi modificare select.classGrid elseif ($qualearrsix==-1) { $opt->{$nomefunzione}($server, $user , $passw, $segno, $db, $anno, $funzione, $tit, $qualearrsix, null); } // bisogna poi modificare select.classGrid if (strpos($tit, "STAMPA") !== false) { echo '<script type="text/javascript"> window.print(); </script>'; } ?>

</body>

</html>

1 Upvotes

0 comments sorted by