Jump to content

need help


Lohmeyer
 Share

Recommended Posts

hi its my first time using PHP and AJAX from the tutorials here. its been wonderful btw i learned alot.but i had this problem when i was making my project and i dont really get why it doesnt work.first of all i followed the sequence on the AJAX tutorial which is HTML -> JAVA -> PHP and then back.. the problem is that the PHP isnt returning the supposed to be new content on the HTML..i dont really know if the JAVA is connecting with the PHP cause i dont know how to check..anyway heres the codes HTML JAVA and PHPHTML -> PlaneTrussAnalysis.html

<html><head><title>Plane Truss Analysis ::  </title><script src="PTA.js"></script></head><body><script language="javascript">var repeat=1 //enter 0 to not repeat scrolling after 1 run, othersise, enter 1var title=document.titlevar leng=title.lengthvar start=1function titlemove() {  titl=title.substring(start, leng) + title.substring(0, start)  document.title=titl  start++  if (start==leng+1) {    start=0    if (repeat==0)    return  }  setTimeout("titlemove()",140)}if (document.title)titlemove()</script><table width="100%" height="100%" style="background-image: url('http://apod.nasa.gov/apod/image/0610/heart_russell_big.jpg'); background-repeat: no-repeat; background-position: center" bgcolor="#000000"><center><tr><td><span id="cont"><table border="2" style="background-image: url('bgblk.png'); background-repeat: repeat; "align="center" cellpadding="10"><tr><td align="right"><font face="Verdana" size="1" color="#FFFFFF"><center>Step 1</center></font><br><form><font face="Verdana" size="1" color="#FFFFFF">Input the total no. of joints:<input type="text" id="NJ" size="20" style="border-left-style:outset; border-left-width:3; background-color: transparent; font-family:Verdana; font-size:7pt; color:#FFFFFF"/><br><br>Input the total no. of members:<input type="text" id="NM" size="20" style="border-left-style:outset; border-left-width:3; background-color: transparent; font-family:Verdana; font-size:7pt; color:#FFFFFF"/><br><br>Input the total no. of joints that have a support:<input type="text" id="NS" size="20" style="border-left-style:outset; border-left-width:3; background-color: transparent; font-family:Verdana; font-size:7pt; color:#FFFFFF"/><br><br>Input the total no. of joints that are subjected to external load:<input type="text" id="NJL" size="20" style="border-left-style:outset; border-left-width:3; background-color: transparent; font-family:Verdana; font-size:7pt; color:#FFFFFF"/><br><br>Input the total no. of material property:<input type="text" id="NMP" size="20" style="border-left-style:outset; border-left-width:3; background-color: transparent; font-family:Verdana; font-size:7pt; color:#FFFFFF"/><br><br>Input the total no. of cross-section property:<input type="text" id="NCP" size="20" style="border-left-style:outset; border-left-width:3; background-color: transparent; font-family:Verdana; font-size:7pt; color:#FFFFFF"/><br><br><input type="hidden" id="step" value="2"><center><input type="submit" value="Step 2 >" style="font-family: Verdana; font-size: 7pt" onclick="getVals()"></center></font></form></td></tr></table></span></td></tr></center></table><script language="javascript">function getVals() {var step = document.getElementById("step").valuevar NJ = document.getElementById("NJ").valuevar NM = document.getElementById("NM").valuevar NS = document.getElementById("NS").valuevar NJL = document.getElementById("NJL").valuevar NMP = document.getElementById("NMP").valuevar NCP = document.getElementById("NCP").valueshowcontent(step,NJ,NM,NS,NJL,NMP,NCP)}</script></body></html>

Javascipt -> PTA.js

var xmlHttpfunction showcontent(step,NJ,NM,NS,NJL,NMP,NCP){ xmlHttp=GetXmlHttpObject()if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return }var url="planetruss.php"alert(url)url=url+"?step="+stepurl=url+"&NJ="+NJurl=url+"&NM="+NMurl=url+"&NS="+NSurl=url+"&NJL="+NJLurl=url+"&NMP="+NMPurl=url+"&NCP="+NCPurl=url+"&sid="+Math.random()xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true)xmlHttp.send(null)}function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {  document.getElementById("cont").innerHTML=xmlHttp.responseText  } }function GetXmlHttpObject(){var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { //Internet Explorer try  {  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  } catch (e)  {  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  } }return xmlHttp;}

PHP -> planetruss.php

<?php$step = $_REQUEST["step"];//step 2if ($step==2){$NJ = $_REQUEST["NJ"];$NM = $_REQUEST["NM"];$NS = $_REQUEST["NS"];$NJL = $_REQUEST["NJL"];$NMP = $_REQUEST["NMP"];$NCP = $_REQUEST["NCP"];echo "<table border=\"2\" align=\"center\" cellpadding=\"65\" height=\"375px\" bgcolor=\"#000000\">";echo "<tr><td align=\"right\">";echo "<font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\"><center>Step 2</center></font><br>";echo "<form>";echo "<div align=\"center\">";echo "<center>";echo "<table border=\"2\" bordercolor=\"#FFFFFF\" width=\"100%\">";echo "<font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">";echo "<tr>";echo "<td width=\"33%\" align=\"center\"><font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">Joint No.</font></td>";echo "<td width=\"33%\" align=\"center\"><font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">X Coordinate (in/m)</font></td>";echo "<td width=\"34%\" align=\"center\"><font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">Y Coordinate (in/m)</font></td>";echo "</tr>";for($i = 1; $i <= $NJ; $i++){echo "<tr>";echo "<td width=\"33%\" align=\"center\"><font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">" . $i . "</font></td>";echo "<td width=\"33%\" align=\"center\">";echo "<font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">";echo "<input type=\"text\" id=\"x" . $i . "\" size=\"20\" style=\"font-family: Verdana; font-size: 7pt\">";echo "</font>";echo "</td>";echo "<td width=\"34%\" align=\"center\">";echo "<font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">";echo "<input type=\"text\" id=\"y" . $i . "\" size=\"20\" style=\"font-family: Verdana; font-size: 7pt\">";echo "</font>";echo "</td>";echo "</tr>";}echo "</font>";echo "</table>";echo "</center>";echo "</div>";echo "<font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">";echo "<br><br>";echo "<input type=\"hidden\" id=\"step\" value=\"3\">";echo "<input type=\"hidden\" id=\"NJ\" value=\"" . $NJ . "\">";echo "<input type=\"hidden\" id=\"NM\" value=\"" . $NM . "\">";echo "<input type=\"hidden\" id=\"NS\" value=\"" . $NS . "\">";echo "<input type=\"hidden\" id=\"NJL\" value=\"" . $NJL . "\">";echo "<input type=\"hidden\" id=\"NMP\" value=\"" . $NMP . "\">";echo "<input type=\"hidden\" id=\"NCP\" value=\"" . $NCP . "\">";echo "<center>";echo "<input type=\"submit\" value=\"Step 3 >\" style=\"font-family: Verdana; font-size: 7pt\"/>";echo "</center>";echo "</font>";echo "</form>";echo "</td></tr>";echo "</table>";} //end of step 2?>

heres the link to the html if you want to see http://farez.x10hosting.com/PlaneTrussAnalysis.htmlalso heres what suppose to replace the contents http://farez.x10hosting.com/planetruss.php...NMP=2&NCP=3(use the test values 6, 10, 3, 3, 2, 3)thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...