cfgcjm Posted June 22, 2008 Share Posted June 22, 2008 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>'; ?> Quote Link to comment Share on other sites More sharing options...
jj20051 Posted June 22, 2008 Share Posted June 22, 2008 Javascript Loads After PHP Does So Your Best Bet Is To Pace The Javascript In A <pre> </pre> Tag and Then Run That Tag Thru PHP... Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted June 22, 2008 Author Share Posted June 22, 2008 it's echoing from ajax so isn't the javascript in the page already loaded? Quote Link to comment Share on other sites More sharing options...
jj20051 Posted June 22, 2008 Share Posted June 22, 2008 No Not Unless You Have Heared Of Some New Way To Do Things That I Can't... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 22, 2008 Share Posted June 22, 2008 Typing Like This Doesn't Make You Seem Like A Better Person. =/ I hate that. Anyway. You're using Ajax to access the page? Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted June 23, 2008 Author Share Posted June 23, 2008 Correct. i'm trying to throw back some values from a database and they need to get thrown into form fields. I wanted to use js by using document.getElementById("curl").value Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted June 23, 2008 Author Share Posted June 23, 2008 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; } } Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 Change it to value and not innerHTML. ._. Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted June 23, 2008 Author Share Posted June 23, 2008 Still nothing... document.getElementById('response').value = resultsuser; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 What exactly are you echoing in the PHP script? Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted June 23, 2008 Author Share Posted June 23, 2008 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>'; Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 23, 2008 Share Posted June 23, 2008 echo '<script language="javascript"> alert("HELLO WORLD");</script>'; should be working... i wonder why its not working for you? ??? Quote Link to comment Share on other sites More sharing options...
cfgcjm Posted June 23, 2008 Author Share Posted June 23, 2008 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) + "¶m2=" + 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>'; ?> Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 25, 2008 Share Posted June 25, 2008 am sorry but am really lazy when it comes to reading long codes. the line that should bring out that alert should be fine. i guess its just never called. try tracing your code (chronologically) and maybe you will find something. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.