Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I tink I have this right but it still doesn't work

Status
Not open for further replies.

Bertiethedog

Programmer
Feb 8, 2007
118
GB
I get the "error on page"

The function "Handle_response" has the correct content so I assume there is something wrong with the "div" statement in the html

eventually I want to load a select menu

I havn't included the file getjob because it appears to work OK

A lot of the code has been copied off this site & I hope nobody minds

Code:
<?php
error_reporting(E_ALL);
$custlst = custlst(0,4);
?>


<html>
<head>
  <title>AJAX - loads a new script!</title>
  <script type="text/javascript" src="ajax_lib.js"></script>
  <style type="text/css">
    #contents {
      width  : 500px;
      height : 100px;
      border : solid 1px #000;
    }
  </style>
</head>
<body>
<p>&nbsp;</p>
     <form name="form1" method="post" action="">
   
     <select onchange="javascript:send_request(this.value)" name="custcode" id="custcode"> 
     <?php print $custlst ;?>
	
     <div class="text" id="contents">Content for class "text" id "contents" Goes Here
	 </div>
    
     </form>
     
</body>
</html>



This is my javascript code in a seperate file

Code:
// JavaScript Document
function createRequestObject() {
  var ro;
  var browser = navigator.appName;
  if(browser == "Microsoft Internet Explorer")
    ro = new ActiveXObject("Microsoft.XMLHTTP");
  else
    ro = new XMLHttpRequest();
  return ro;
}

function send_request(html_file_name) {
  server_side_script = 'getjob.php?filename=' + html_file_name;
  http.open('get', server_side_script);
  http.onreadystatechange = handle_response;
  http.send(null);
 
}

var http = createRequestObject();

function handle_response() {
  if(http.readyState == 4){
    var response = http.responseText;
	var parts = response.split('~');
	
    if(parts.length>1) {
      load_script(parts[0]);
*-********* An alert at this point has the correct content

	  document.getElementById("contents").innerHTML = parts[1];
    } else {
			  
      document.getElementById("contents").innerHTML = response;
    }
  }
  
}

function load_script(filename) {
  var script = document.createElement('script'); 
  script.type = 'text/javascript'; 
  script.src = filename; 
  document.getElementsByTagName('head')[0].appendChild(script);
}
 
Sorry about the heading I couldn't spell yesterday



Code:
<select onchange="javascript:send_request(this.value)" name="custcode" id="custcode"> 
     <?php print $custlst ;?>

I had omitted the </select> after the previous bit of code, what confused me is that selection box actually worked it just prevented anything else from happening

Thanks everyone I will get there eventually

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top