Bug #67598 [Opn->Nab]: Bug with Javascript and PHP

From: Date: Wed, 09 Jul 2014 20:55:54 +0000
Subject: Bug #67598 [Opn->Nab]: Bug with Javascript and PHP
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186548@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67598&edit=1

 ID:                 67598
 Updated by:         requinix@php.net
 Reported by:        matias dot seguel dot estay at gmail dot com
 Summary:            Bug with Javascript and PHP
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Windows 7
 PHP Version:        5.5.14
 Block user comment: N
 Private report:     N

 New Comment:

As long as you don't mind an English reply :)


  <button
onClick='oracion('$variable1','$variable2','$variable3');'
>

You can't put ' quotes in your Javascript code if you use them for the onclick value.
It's confusing to the browser and results in that space you see.

The easiest solution is to use escaped " quotes (\"), like
  "<button
onClick='oracion(\"$variable1\",\"$variable2\",\"$variable3\");'
>"
or
  "<button
onClick=\"oracion('$variable1','$variable2','$variable3');\"
>"


Previous Comments:
------------------------------------------------------------------------
[2014-07-09 20:37:38] matias dot seguel dot estay at gmail dot com

Description:
------------
Hi, i don't speak English very well , so i'll write the bug in spanish. 

sorry for the inconvenience.


Hola, soy de Chile, trabajo en para una empresa de Informatica, y en uno de mis desarrollos, me he
dado cuenta de un problema.

Al crear variables PHP de tipo "string", y pasarlas a través de una funcion javascript
desde una ejecucion "onClick" por ejemplo, a la primera variable php se le agrega un
ESPACIO, que impide la correcta ejecución de la funcion javascript.

Mas abajo dejo un pequeño test script que hice para que vean el problema.

Si el problema es mio, debido a mi falta de conocimientos, les pido disculpas.

Agradecería tener un pequeño reporte a mi email por favor. 

Test script:
---------------
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
function oracion(a,b,c)
{
	var resultado = a + b + c ;
	alert(resultado);
}
</script>
</head>

<body>
<?php
	$variable1 = "hola";
    $variable2 = "como";
    $variable3 = "estas?";
	echo "<button
onClick='oracion('$variable1','$variable2','$variable3');'
>Clickme </button>"
?>
</body>
</html>

Expected result:
----------------
Se espera que se ejecute correctamente la funcion javascript

Actual result:
--------------
No se ejecuta la funcion javascript debido a que se genera un espacio en la primera variable
entregada.

(Inspeccionar codigo en tiempo de ejecución en Google Chrome (ejemplo) para verificar lo que
digo).


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=67598&edit=1


Thread (3 messages)

« previous php.bugs (#186548) next »