php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67598 Bug with Javascript and PHP
Submitted: 2014-07-09 20:37 UTC Modified: 2014-07-10 13:10 UTC
From: matias dot seguel dot estay at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.14 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matias dot seguel dot estay at gmail dot com
New email:
PHP Version: OS:

 

 [2014-07-09 20:37 UTC] 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).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-09 20:55 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-07-09 20:55 UTC] requinix@php.net
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');\" >"
 [2014-07-10 13:10 UTC] matias dot seguel dot estay at gmail dot com
This comment is just for say thank you, i really appreciate your reply and your friendliness.

Thanks!
Gracias :)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 17:00:01 2026 UTC