Non volevo riempire pagine di codice, pensavo che fosse sufficiente il concetto. Ecco parti del codice. Supponendo di cliccare sul link "user_list" del File1 viene richiamata la pagina File2 che esegue la query per estrarre la lista degli utenti. File2 a sua volta richiama la pagina File3 che mostra la lista degli utenti.
Io vorrei inserire del codice javascript nel File3. Un campo di input con una validazione di testo (esempio utilizzando la classe livevalidation che trovi qui http://livevalidation.com/examples).
Se lo inserisco il javascript non ha nessun effetto.
File 1:
************************************************** ***********
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<title><?php echo ADMIN_PANEL_LABEL; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta name="author" content="Douglas Rennehan" />
<link rel="stylesheet" type="text/css" href="html/tabbed_pane.css" />
<script language="JavaScript" type="text/javascript">
/**
* @var object sub_menu - It will contain the DIV element
*/
var sub_menu;
/**
* @var object ajax - Contains the AJAX information
*/
var ajax;
/**
* @var string current_selection - Contains the current tab
*/
var current_selection = "tab1";
/**
* @var array links - Contains all the sub menu links
*/
var links = new Array();
/**
* These all contain the sub menus for the tabs. You
* can change it around if necessary but it should be
* left the way it is
*/
links["tab2"] = new Array();
links["tab2"][0] = '<?php echo ADD_LABEL; ?>';
links["tab2"][1] = '<?php echo LIST_LABEL; ?>';
/**
* Opens a URL and reads the information
* @param string url - The URL to open
* @return void
*/
function run_ajax(url) {
var ajax;
try {
ajax = new XMLHttpRequest();
}
catch (e) {
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("<?php echo BROWSER_NO_AJAX; ?>");
}
}
}
ajax.onreadystatechange = function() {
if (ajax.readyState == 1) {
document.getElementById("page_content").innerHTML = "<?php echo LOADING_LABEL; ?>...";
}
if (ajax.readyState == 4) {
document.getElementById("page_content").innerHTML = ajax.responseText;
}
}
ajax.open("GET", url, true);
ajax.send(null);
}
/**
* Acts like submitting a form
* @param string page - The area in the admin panel to open
* @param array params - The params that need to be processed
* @return void
*/
function run_form(page, params) {
var query_string = "";
var current_param;
for (var x in params) {
current_param = params[x];
query_string += "&" + current_param + "=" + encodeURI(document.getElementById(current_param).v alue);
}
var url = "file2.php?do=" + page + "&type=process" + query_string;
run_ajax(url);
}
/**
* Loads a page in the admin panel
* @param string page - The area to open
* @return void
*/
function load_page(page) {
var url = "file2.php?do=" + page;
run_ajax(url);
}
/**
* The event when a tab is clicked (opens the sub menu)
* @param integer tab_id - The tab ID
* @return void
*/
function click_tab(tab_id) {
document.getElementById(current_selection).classNa me = "tab_unselected";
document.getElementById(tab_id).className = "tab_selected";
current_selection = tab_id;
sub_menu = document.getElementById("sub_menu");
sub_menu.innerHTML = "";
for (var x in links[tab_id]) {
sub_menu.innerHTML += links[tab_id][x] + "";
}
}
setTimeout("click_tab('tab1')", 1000);
//-->
</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" id="tabs">
<tr>
<td class="hidden">
</td>
<td id="tab1" class="tab_selected" onclick="javascript:click_tab('tab1');">
<?php echo MAIN_LABEL; ?>
</td>
<td class="hidden">
</td>
<td id="tab2" class="tab_unselected" onclick="javascript:click_tab('tab2');">
<?php echo USERS_LABEL; ?>
</td>
<td class="hidden">
</td>
<td class="hidden">
</td>
<td class="hidden">
</td>
</tr>
<tr>
<td colspan="17" id="sub_menu">
</td>
</tr>
<tr>
<td colspan="17">
<hr noshade="noshade" width="100%" />
</td>
</tr>
<tr>
<td colspan="17" id="page_content">
<?php echo ADMIN_PANEL_WELCOME; ?>
</td>
</tr>
</table>
</body>
</html>
************************************************** ***********************
File2:
************************************************** ***********************
switch ($_GET['do']) {
case 'user_list':
$users_result = $qls->SQL->query("SELECT * FROM `{$qls->config['sql_prefix']}users` ORDER BY `id` DESC LIMIT {$offset},{$perpage}");
require_once('html/File3.php');
break;
************************************************** ***********************
File3:
*************
<fieldset>
<legend>
<?php echo USER_LIST_LABEL; ?>
</legend>
<?php
$users_count = $qls->SQL->num_rows($users_result);
if ($users_count == 0) {
echo GROUP_USER_LIST_NO_USERS;
}
else {
?>
<table border="0" cellspacing="3" cellpadding="2">
<tr>
<th style="border-right: 1px solid #000;text-align:left;"><?php echo USERNAME_LABEL; ?></th>
<th style="border-left: 1px solid #000;text-align:left;"><?php echo ADD_LABEL; ?></th>
</tr>
<?php
// $users_result is provided by groupcp.php
while ($users_row = $qls->SQL->fetch_array($users_result)) {
?>
<tr>
<td align="left"><?php echo stripslashes($users_row['username']); ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</fieldset>
************************************************** ***********