Non devo recuperare delle variabili dall'url, ma bensì utilizzare
funzioni presenti in un file js, da richiamare o includere nella pagina.
Ad esempio controlli su form o messaggi.
Ho già utilizzato in passato i file esterni di js includendo il file js in questo modo:
<script language="javascript" type="text/javascript" src="xxx.js"></script>
oppure passando una variabile:
<script language="javascript" type="text/javascript" src="xxx.js?var"></script>
e funzionano;
In questo caso i controlli sul form e il proseguimento della procedura di update vengono fatti ma solo la prima volta e non capisco perchè;
Ecco cosa faccio:
- nella pop up ho un frame top ove carico il menu che comanda la pagina inferiore nel frame centrale questo è il codice:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function sx() {
top.menuwf.document.location="me_wf.php?t=<?echo$H TTP_GET_VARS["t"]?>&id=<?echo$id?>";
top.mainwf.document.location="<?echo $HTTP_GET_VARS["f"]?>?id=<?echo$id?>";
}
var t ='<?echo$HTTP_GET_VARS["t"]?>';
-->
</script>
<script language="javascript" type="text/javascript" src="vconf.js?t"></script>
</head>
<body bgcolor="#CAE4FF">
<div id="Layer1" style="position:absolute; width:595px; height:30px; z-index:1; left: 8px; top: 5px">
<table width="180" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="65">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2">Indietro</font></div>
</td>
<td width="65">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2">Conferma</font></div>
</td>
</tr>
</table>
</div>
</body>
</html>
Il file "vconf.js?t" controlla i valori nel form secondo la variabile passata:
var form = top.mainwf.document.f1;
if (t == 'Iva') {
function cf () {
if (!check(form)) return;
top.mainwf.document.f1.submit();
return;
}
function check(form) {
if (form.des.value == 0) {
alert ("Digitare Descrizione!");
form.des.focus();
return (false);
}
if (form.iva.value == 0) {
alert ("Digitare Aliquota!");
form.iva.focus();
return (false);
}
return(true);
}
}
Nel frame centrale ho la form per le modifiche che punta al file per l'update:
<?
session_start();
header("Pragma: no-cache",false);
include ('he.inc');
$tt = '';
ht($tt);
include ('fc.php');
$conn = connetti();
$qy = mysql_query("SELECT des, iva FROM t_iva WHERE cd_iva='$HTTP_GET_VARS[cd]'");
$r = mysql_fetch_array($qy);
?>
</head>
<body>
<form name='f1' action='t_iva_up.php' method='post'>
<input type='hidden' name='cd' value='<?echo $HTTP_GET_VARS["cd"]?>'>
<input type='hidden' name='id' value='<?=$id?>'>
<div id='Layer2' style='position:absolute; width:440px; height:250px; z-index:2; left: 200px; top: 50px'>
<table>
<tr>
<td class=testo1>Descrizione:</td>
<td><input type="text" class=campo name="des" maxlength="15" size="15" value='<?echo$r[des]?>'></td>
</tr>
<tr>
<td class=testo1>Aliquota:</td>
<td><input type="text" class=campo name="iva" maxlength="2" size="15" value='<?echo$r[iva]?>'></td>
</tr>
</table>
</div>
<script language="JavaScript">
<!--
self.window.focus();
f1.des.focus();
-->
</script>
</form>
</body>
</html>
- File per l'update in db:
<?
session_start();
header("Pragma: no-cache",false);
include ('fc.php');
$conn = connetti();
$qy = mysql_query("SELECT cd_iva FROM t_iva WHERE (upper(trim(des))=upper(trim('$HTTP_POST_VARS[des]')))
AND (upper(trim(iva))=upper(trim('$HTTP_POST_VARS[iva]')))");
if ( (mysql_num_rows($qy) > 0) && ($HTTP_GET_VARS["cd"] != $r["cd_iva"]) ) { ?>
<html><head>
<script language="JavaScript">
<!--
function back() {
top.menuwf.document.location="me_wf.php?t=Iva&id=< ?echo$id?>";
top.mainwf.document.location="t_iva.php?id=<?echo$ id?>";
}
var ms=1;
-->
</script>
</head>
<body bgcolor='#DDEEFF'>
<script language="javascript" type="text/javascript" src="mes.js?ms"></script>
</body>
</html>
<?
} else {
$qy = mysql_query("UPDATE t_iva SET des='$HTTP_POST_VARS[des]',iva='$HTTP_POST_VARS[iva]' WHERE cd_iva='$HTTP_GET_VARS[cd]'");
if (mysql_errno() == 0) { ?>
<script language="JavaScript">
<!--
top.menuwf.document.location="me_wf.php?t=Iva&id=< ?echo$id?>";
top.mainwf.document.location="t_iva.php?id=<?echo$ id?>";
-->
</script>
<?
} else { ?>
<html><head>
<script language="JavaScript">
<!--
function back() {
top.menuwf.document.location="me_wf.php?t=Iva&id=< ?echo$id?>";
top.mainwf.document.location="t_iva.php?id=<?echo$ id?>";
}
var ms=2;
-->
</script>
</head>
<body bgcolor='#DDEEFF'>
<script language="javascript" type="text/javascript" src="mes.js?ms"></script>
</body>
</html>
<?
}
}
mysql_close();
?>

Rispondi quotando