PHP - Problema llamando funcion de Javascript

 
Vista:

Problema llamando funcion de Javascript

Publicado por Marlo (5 intervenciones) el 04/12/2013 22:00:15
Buenas tengo una rutina que elimina un registro de a través de una búsqueda y quisiera ponerle una función Javascript que me muestre un mensaje de confirmación antes de hacer el borrado, tengo el código montado pero no me muestra el mensaje en ningún momento.

A continuación el código:

1
2
3
4
5
6
7
8
9
10
<script language='javascript'>
function ConfirmChoice()
	{
		answer = confirm('Quieres borrar este registro?')
		if (answer !=0)
	{
		location = 'borrar.php?id=<?php echo $row_busqueda_nombre['id']; ?>'
	}
}
</script>

Aquí llamo la función:

1
<td width='40'><a href='borrar.php?id=<?php echo $row_busqueda_nombre['id']; ?>' ><img src='images/iconos/Symbol - Delete.png' alt='Borrar Registro' width='40' height='40' border='0' onclick='return ConfirmChoice()'/></a></td>


Si tienen algún comentario les agradecería
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema llamando funcion de Javascript

Publicado por xve (6935 intervenciones) el 04/12/2013 22:38:13
Hola Mario, he probado tu código en una simple pagina y me ha funciona perfectamente...

Donde tienes puesta la función javascript en la página?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Problema llamando funcion de Javascript

Publicado por Elier (92 intervenciones) el 05/12/2013 15:31:47
Revisa que tengas activado Javascript en tu Navegador.

Reviste tu código, revisa si esta correcto.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html>
<head>
<script>
function ConfirmChoice() {
 answer = confirm('Quieres borrar este registro?')
 if (answer !=0)
 {
 return true;
 }
 return false;
}
</script>
</head>
<body>
<td width='40'><a href='borrar.php?id=<?php echo $row_busqueda_nombre['id']; ?>' ><img src='images/iconos/Symbol - Delete.png' alt='Borrar Registro' width='40' height='40' border='0' onclick='return ConfirmChoice()'/></a></td>
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema llamando funcion de Javascript

Publicado por Marlo (5 intervenciones) el 05/12/2013 15:35:57
Este es el Script COMPLETO:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<?php require_once('Connections/coneccion.php'); ?>

<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF'].'?doLogout=true';
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != '')){
$logoutAction .='&'. htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=='true')){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);

$logoutGoTo = 'index.php';
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = '';
$MM_donotCheckaccess = 'true';

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(',', $strUsers);
$arrGroups = Explode(',', $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == '') && true) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = 'index.php';
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized('',$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = '?';
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, '?')) $MM_qsChar = '&';
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= '?' . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . 'accesscheck=' . urlencode($MM_referrer);
header('Location: '. $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists('GetSQLValueString')) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = '', $theNotDefinedValue = '')
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists('mysql_real_escape_string') ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case 'text':
$theValue = ($theValue != '') ? "'" . $theValue . "'" : 'NULL';
break;
case 'long':
case 'int':
$theValue = ($theValue != '') ? intval($theValue) : 'NULL';
break;
case 'double':
$theValue = ($theValue != '') ? doubleval($theValue) : 'NULL';
break;
case 'date':
$theValue = ($theValue != '') ? "'" . $theValue . "'" : 'NULL';
break;
case 'defined':
$theValue = ($theValue != '') ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$currentPage = $_SERVER['PHP_SELF'];

$colname_busqueda_nombre = '-1';
if (isset($_POST['cirif_documento'])) {
$colname_busqueda_nombre = $_POST['cirif_documento'];
}
mysql_select_db($database_coneccion, $coneccion);
$query_busqueda_nombre = sprintf('SELECT id, empresa, cirif_documento FROM datos WHERE cirif_documento LIKE %s ORDER BY empresa DESC', GetSQLValueString('%' . $colname_busqueda_nombre . '%', 'text'));
$busqueda_nombre = mysql_query($query_busqueda_nombre, $coneccion) or die(mysql_error());
$row_busqueda_nombre = mysql_fetch_assoc($busqueda_nombre);
$totalRows_busqueda_nombre = mysql_num_rows($busqueda_nombre);

$queryString_busqueda_nombre = '';
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode('&', $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, 'pageNum_busqueda_nombre') == false &&
stristr($param, 'totalRows_busqueda_nombre') == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_busqueda_nombre = '&' . htmlentities(implode('&', $newParams));
}
}
$queryString_busqueda_nombre = sprintf('&totalRows_busqueda_nombre=%d%s', $totalRows_busqueda_nombre, $queryString_busqueda_nombre);
?>

<script type='text/javascript' src='js/jquery-1.8.3.js'></script>
<style type='text/css'></style>

<script language=\"Javascript\">
function preguntar(){
eliminar=confirm(\"¿Deseas eliminar este registro?\");
if (eliminar)
//Redireccionamos si das a aceptar
window.location.href = \"borrar.php?id=<?php echo $row_busqueda_nombre['id']; ?>"; //página web a la que te redirecciona si confirmas la eliminación
else
//Y aquí pon cualquier cosa que quieras que salga si le diste al boton de cancelar
alert(\'No se ha podido eliminar el registro...\')
}
</script>

<script type='text/javascript'>
function writeHTMLHF() {
$('#HideButtons').hide();
$('#HFIndice').val($('#indice').val());
$('#HFCode').val($('#pdftag').html());
}
</script>
<script type='text/javascript'>
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<script language='javascript'>
function ConfirmChoice()
{
answer = confirm('Quieres borrar este registro?')
if (answer !=0)
{
location = 'borrar.php?id=<?php echo $row_busqueda_nombre['id']; ?>'
}
}
</script><link rel='stylesheet' type='text/css' href='style.css'>
<body id='art-main'>
<table width='650' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td colspan='2' align='left'><img src='images/logo_sistema.png' width='313' height='91' style='margin:10px;' /></td>
<td align='right'><img src='images/LOGOORIGINAL.png' width='224' height='58' /></td>
</tr>
<tr>
<td width='237' height='41'><ul class='art-hmenu'><li><a href='index_2.php'>volver</a></li></ul></td>
<td width='250'>&nbsp;</td>
<td width='163'><ul class='art-hmenu'><li><a href='<?php echo $logoutAction ?>' >Desconectar</a></li></ul></td>
</tr>
</table>
<form id='form1' name='form1' method='post' action=''>
<table width='550' border='0' align='center' cellpadding='4' cellspacing='0'>
<tr>
<td width='274' height='50' align='right' >Busqueda por RIF o Cedula</td>
<td width='276' align='left'><input name='cirif_documento' type='text' id='cirif_documento' /></td>
</tr>
<tr>
<td colspan='2'><input type='reset' name='Reset' id='button' value='BORRAR' />
<input type='submit' name='button2' id='button2' value='BUSCAR REGISTRO' /></td>
</tr>
</table>
</form>

<?php if ($totalRows_busqueda_nombre > 0) { // Show if recordset not empty ?><?php do { ?>
<table width='650' border='0' align='center' cellpadding='5' cellspacing='0'>
<tr>
<td width='160' ><?php echo $row_busqueda_nombre['cirif_documento']; ?></td>
<td width='270' ><?php echo strtoupper($row_busqueda_nombre['empresa']); ?></td>
<td width='40'><a href='editar.php?id=<?php echo $row_busqueda_nombre['id']; ?>' target='_blank' ><img src='images/iconos/Edit_Yes.png' alt='Editar Registro' width='40' height='40' border='0' /></a></td>
<td width='40'><a href='cambiar_imagen.php?id=<?php echo $row_busqueda_nombre['id']; ?>' target='_blank' ><img src='images/iconos/Photo.png' alt='Cambiar Imagen del Registro' width='40' height='40' border='0' /></a></td>
<td width='40'><a href='descarga.php?id=<?php echo $row_busqueda_nombre['id']; ?>' target='_blank' ><img src='images/iconos/PDF-Download.png' alt='Generar Reporte' width='40' height='40' border='0' onClick='MM_openBrWindow','REPORTE','scrollbars=yes,width=605,height=785' /></a></td>
<!-- <td width='40'><a href='link.php?id=<?php echo $row_busqueda_nombre['id']; ?>' target='_blank' ><img src='images/iconos/PDF-Icon.png' alt='Cambiar Imagen del Registro' width='40' height='40' border='0' /></a></td> -->
<td width='40'><a href='\"javascript:preguntar()\"' ><img src='images/iconos/Symbol - Delete.png' alt='Borrar Registro' width='40' height='40' border='0' onclick='return ConfirmChoice('¿Estas seguro?')'/></a></td>
</tr
</table>
<?php } while ($row_busqueda_nombre = mysql_fetch_assoc($busqueda_nombre)); ?>

<?php } // Show if recordset not empty ?>

</body>
<?php
mysql_free_result($busqueda_nombre);
?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar