Jump to content

echo js in php problem


cfgcjm

Recommended Posts

I'm trying to echo javascript back to for php and it's not providing either a result nor an error...any ideas?

 

<?PHP
session_start();
//Call dbconnection powerscript
require_once "connect.php";
$lastname = urldecode($_GET['param']);
$firstname = urldecode($_GET['param2']);

echo '<script type="text/javascript">
alert("HELLO WORLD");</script>'; 
?>

Link to comment
https://forums.phpfreaks.com/topic/111405-echo-js-in-php-problem/
Share on other sites

So you do:

 

echo "some value";

 

On the PHP page, then on the ajax, you do:

 

var response = http.responseText;

e = document.getElementById("someelement");

if(response!=""){

e.value=response;

 

} else {

 

}

 

If http was your request object and somelement was your form input ID.  (Assign an ID so it's easier.

Ok I'll post my whole sha-bang and maybe someone can see something:

 

Form that calls the ajax function:

<div id="box" style="display:none">
    <p id="close" onclick="hideBox()">Close</p>
    <p class="label">Student: </p><form action="" method="get">
    		<select name="stdname" id="stdname" onchange="openrecord();">
		<option></option>
		<?php
		for ($j=0; $j<$i; $j++) {
		echo "<option value='{$student[$j][0]}'>{$student[$j][0]}</option>";
		}
		?>
		</select>
    </form>
</div>

 

 

JS file

function openrecord(){
var student=document.getElementById('stdname').value;
var result_array=student.split(", ");

var lastname=result_array[0];
var firstname=result_array[1];

var url = "http://recorded-live.com/fitness/scripts/open.php?param=";


http.open("GET", url + escape(lastname) + "&param2=" + escape(firstname), true);
http.onreadystatechange = handleHttpResponseUser;
http.send(null);

}

function handleHttpResponseUser() {
if (http.readyState == 4) {
resultsuser = http.responseText;
if(resultsuser == "") resultsuser = "Blank";
document.getElementById('response').value = resultsuser;
}
}

function getHTTPObjectUser() {
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {xmlhttp = new XMLHttpRequest();} catch (e) {xmlhttp = false;}
}

if(!xmlhttp && typeof ActiveXObject != "undefined"){
   try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
   if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
  }
  
return xmlhttp;
}
var http = getHTTPObjectUser();

 

 

open.php

<?php
session_start();
//Call dbconnection powerscript
require_once "connect.php";
$lastname = urldecode($_GET['param']);
$firstname = urldecode($_GET['param2']);

echo '<script type="text/javascript">
alert("HELLO WORLD");</script>'; 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.