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
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.

Link to comment
Share on other sites

This is the 2nd function of my ajax js

 

function handleHttpResponseUser() {

if (http.readyState == 4) {

resultsuser = http.responseText;

if(resultsuser == "") resultsuser = "Blank";

document.getElementById('response').innerHTML = resultsuser;

}

}

Link to comment
Share on other sites

right now this is what i'm trying to echo

 

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

 

 

but eventually it will be

 

echo '<script type="text/javascript">

document.getElementById('curl').value=$variable;</script>';

Link to comment
Share on other sites

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>'; 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.