Ejemplo de código fuente en php y JavaScript que al hacer click en un button, nos muestra en una caja de texto o input text, una string generada desde una función php.
ÍNDICE
Código
<?php
function funcionPHP(){
$str = "Hola Mundo desde PHP";
return $str;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="robots" content="noindex,nofollow"/>
<!--[if ie]><meta content='IE=8' http-equiv='X-UA-Compatible'/><![endif]-->
<title>Mostrar cadena en textbox desde función php - EjemploCodigo</title>
</head>
<body>
<script>
function funcionJS(elem){
elem.value = "<?php echo funcionPHP(); ?>";
elem.style.backgroundColor = "#eee";
elem.style.borderColor = "#7ad03a";
}
</script>
<p>
<input type="text" id="nombre" name="nombre" size="30" />
</p>
<p>
<input type="button" id="boton" name="boton" value="Ejecutar funcion PHP" onclick="funcionJS(document.getElementById('nombre'));" />
</p>
</body>
<html>
Demo