Jump to content

Problem getting Ajax value to pass... Is it a php error or an Ajax error


DBookatay

Recommended Posts

As the title say, I can not for the life of me get the "$bank" content to display, no matter HOW much I try...

Does anyone see any errors. I am sooooooo wiped out at this!

 

 

main page

<?
$body = '

		<script type="text/javascript" src="change-content.js"></script>

		<div id="addSold">
		<form action="'.$_SERVER['REQUEST_URI'].'" method="post" name="form" autocomplete="off">

			<fieldset id="Vehicle">
				<legend>Vehicle</legend>
				<ul>
					<li><label for="Year">Year</label>'.$Year.'</li>
					<li><label for="Make">Make</label>'.$Make.'</li>
					<li><label for="Model">Model</label>'.$Model.'</li>
					<li><label for="Trim">Trim</label><input type="text" name="Trim" id="Trim" size="10" value="'.$trim.'" disabled="disabled"></li>
				</ul>
				<ul>
					<li><label for="Mileage">Mileage</label><input type="text" name="Mileage" id="Mileage" size="5" maxlength="6" value="'.$row['mileage'].'"></li>
					<li><label for="VIN">VIN</label><input type="text" name="VIN" id="VIN" size="23" maxlength="17" value="'.$row['vin'].'" disabled="disabled"></li>
					<li><label for="Color">Color</label>'.$Exterior.'</li>
				</ul>
			</fieldset>

			<fieldset id="Deal">
				<legend>Deal</legend>
				<ul>
					<li>
						<label for="soldDte1">Date</label>
						<input type="text" name="soldDte1" id="soldDte1" size="1" maxlength="2" onkeyup="return autoTab(this, 2, event)" value="08"> / 
						<input type="text" name="soldDte2" id="soldDte2" size="1" maxlength="2" onkeyup="return autoTab(this, 2, event)" value="30"> / 
						<input type="text" name="soldDte3" id="soldDte3" size="1" maxlength="2" value="'.$year.'">
						<a href="#"><img id="date_'.$row[stock].'" src="images/Icons/dateOff.png" onfocus="this.select();lcs(this)" onmouseover="MM_swapImage(\'date_'.$row[stock].'\',\'\',\'images/Icons/dateOn.png\',1)" onmouseout="MM_swapImgRestore()" alt="Choose Date"></a>
					</li>
					<li>
						<label for="salesman">Salesman</label> 
						<select name="salesman" id="salesman">
							<option></option>
							'.$salesmen.'
						</select>
					</li>
				</ul>
				<ul>
					<li>
						<label for="dealType">Deal Type</label>
						<select name="dealType" class="select-content" onchange="getFile(this.value)">
							<option></option>
							<option value="AL">Auto Loan</option>
							<option value="Cash">Cash</option>
							<option value="CAC">Credit Acceptance</option>
							<option value="IH">In House</option>
							<option value="SAL">Sensible Auto</option>
						</select>
					</li>
					<li>
						<label for="tradeDrop">Trade</label> 
						<select name="tradein" id="tradeDrop" onchange="show_hide_trade(this.value);">
							<option value="No">No</option>
							<option value="Yes">Yes</option>
						</select>
					</li>
				</ul>
			</fieldset>

			<div id="Bank" class="view">'.$bank.'</div>
		</form>
		</div>
	';
?>

 

get_Bank.php

<?
if ($_GET['dealType'] == "AL") {
	$bank = '
		<fieldset id="AL">
			<legend>Auto Loan Figures</legend>
			<ul>
				<li><label for="price">Price</label><input type="text" name="price" id="price" class="price" size="7" onchange="currency(this)"></li>
				<li><label for="down">Down</label><input type="text" name="down" id="down" class="price" size="6" onchange="currency(this)"></li>
				<li><label for="tax">Tax</label><input type="text" name="tax" id="tax" class="price" size="6" onchange="currency(this)"></li>
				<li><label for="reg">Plates</label><input type="text" name="reg" id="reg" class="price" size="4" onchange="currency(this)"></li>
				<li><label for="gap">Gap</label><input type="text" name="gap" id="gap" class="price" size="4" onchange="currency(this)"></li>
			</ul>
			<ul>
				<li>
					<label for="pymtNum">--------------- Payment ---------------</label>
					<input type="text" name="pymtNum" id="pymtNum" size="3" maxlength="3" onkeyup="return autoTab(this, 3, event)"> @ 
					<input type="text" name="pymtAmnt" id="pymtAmnt" class="price" size="5" onchange="currency(this)"> per 
					<select name="pymtType">
						<option value="Weekly" selected="selected">Week</option>
						<option value="Monthly">Month</option>
					</select>
				</li>
				<li><label for="APR">APR</label><input type="text" name="APR" id="APR" class="rate" size="6" value="19.00"></li>
			</ul>
		</fieldset>
	';
} elseif ($_GET['dealType'] == "CAC") {
	$bank = '
		Credit Acceptance stuff goes here
	';
} else {
	$bank = 'You must choose a bank before continuing';
}

?>

 

change-content.js

window.onload = init;

// finds all <select> tags will class="select-content" and activates function
function init() {
var sel = document.getElementsByTagName("select");
for (var i=0; i<sel.length; i++){
	if (sel[i].className == "select-content") {
		sel[i].onchange = getFile;
	}
	sel[i].selectedIndex = 0;	
}
}

function getFile (url) {
var url = "AJAX/get_Bank.php?dealType="+ this.value;
if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();}
else {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

xmlhttp.open("GET",url,false);
xmlhttp.send();

// a loop that looks through all <div>s on the page
// and then replaces the id with the value and gets that file
var divs = document.getElementsByTagName("div");
for (var i=0; i<divs.length; i++) {
	if(divs[i].id == "bank") {
		divs[i].id = this.value;
		divs[i].innerHTML=xmlhttp.responseText;
	}
}
}

Link to comment
Share on other sites

You really should use the full php tags (<?php) - but thats completely unrelated, anywho;

 

get_Bank.php

<?
if ($_GET['dealType'] == "AL") {
	$bank = '
		<fieldset id="AL">
			<legend>Auto Loan Figures</legend>
			<ul>
				<li><label for="price">Price</label><input type="text" name="price" id="price" class="price" size="7" onchange="currency(this)"></li>
				<li><label for="down">Down</label><input type="text" name="down" id="down" class="price" size="6" onchange="currency(this)"></li>
				<li><label for="tax">Tax</label><input type="text" name="tax" id="tax" class="price" size="6" onchange="currency(this)"></li>
				<li><label for="reg">Plates</label><input type="text" name="reg" id="reg" class="price" size="4" onchange="currency(this)"></li>
				<li><label for="gap">Gap</label><input type="text" name="gap" id="gap" class="price" size="4" onchange="currency(this)"></li>
			</ul>
			<ul>
				<li>
					<label for="pymtNum">--------------- Payment ---------------</label>
					<input type="text" name="pymtNum" id="pymtNum" size="3" maxlength="3" onkeyup="return autoTab(this, 3, event)"> @ 
					<input type="text" name="pymtAmnt" id="pymtAmnt" class="price" size="5" onchange="currency(this)"> per 
					<select name="pymtType">
						<option value="Weekly" selected="selected">Week</option>
						<option value="Monthly">Month</option>
					</select>
				</li>
				<li><label for="APR">APR</label><input type="text" name="APR" id="APR" class="rate" size="6" value="19.00"></li>
			</ul>
		</fieldset>
	';
} elseif ($_GET['dealType'] == "CAC") {
	$bank = '
		Credit Acceptance stuff goes here
	';
} else {
	$bank = 'You must choose a bank before continuing';
}

// the javascript needs to be able to get the result 
echo $bank;

?>

 

I'm not sure if your javascript is sound as im not as fluent in javascript :P.

Looking at some tutorials im sure you can check that too ;).

 

hope this helps

Link to comment
Share on other sites

So it would seem your javascript is not workign properly, do you get any errors from the java console in your browser? (firefox is Awesome for developers of java!).

 

use the javascript: alert() to help debug your code like so:

 

function getFile (url) {
   var url = "AJAX/get_Bank.php?dealType="+ this.value;
   alert("getFile( " + url + " );");
   if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();}
   else {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

   xmlhttp.open("GET",url,false);
   xmlhttp.send();
   
   // a loop that looks through all <div>s on the page
   // and then replaces the id with the value and gets that file
   var divs = document.getElementsByTagName("div");
   for (var i=0; i<divs.length; i++) {
      if(divs[i].id == "bank") {
         alert("(divs[i].id == bank - response text: " + xmlhttp.responseText);
         divs[i].id = this.value;
         divs[i].innerHTML=xmlhttp.responseText;
      }
   }
}

 

I believe your missing some javascript required for the AJAX functions to work.

Link to comment
Share on other sites

You are not getting the alert?! Then there is likely a javascript compile error. What browser are you using? It should have an error icon to indicate a JS error.

 

I see a couple of problems

 

function getFile (url) {
var url = "AJAX/get_Bank.php?dealType="+ this.value;
if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();}

You are passing a value to this function - but it is not being used. You are overwriting the value passed to the function on the first line. I think you mean to append the passed value on the end of that string. I don't even think this.value would work in that context. So, use a different var name for the input var and do something like this

function getFile (urlInput) {
var url = "AJAX/get_Bank.php?dealType="+ urlInput;
if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();}

 

Also, the page get_Bank.php defines a variable $bank, but doesn't do anything with it. You need to echo the variable to have it passed back to the JavaScript code.

Link to comment
Share on other sites

I'm using IE9 beta and FF 3.6.3 and was not getting any errors on my pc.

I used a different pc with IE 7 and got the following error:

 

Message: Object expected

Line: 131

Char: 1

Code: 0

URI: http://www.login.carcityofdanbury.com/passed/index.php?category=001&display=Sold&stock=17561

 

Line 131 is: <select name="dealType" class="select-content" onchange="getFile(this.value)">

 

 

Link to comment
Share on other sites

I'm using IE9 beta and FF 3.6.3 and was not getting any errors on my pc.

I used a different pc with IE 7 and got the following error:

 

Message: Object expected

Line: 131

Char: 1

Code: 0

URI: http://www.login.carcityofdanbury.com/passed/index.php?category=001&display=Sold&stock=17561

 

Line 131 is: <select name="dealType" class="select-content" onchange="getFile(this.value)">

 

Right, as I suspected there is a problem that prevents the JavaScript from being compiled correctly. So, it isn't being run . . . at all. Where that error is can be difficult to determine. I don't see anything that jumps out at me from the code above. If there is any JS code that you have not posted above the problem behat code.

 

The first step I would take to debug this problem would be to install the Firebug extension for Firefox. That is a great tool for JS debugging. If that doesn't help, then I would suggest commenting out sections of code until you can get the JS to run. Once it starts to run then uncomment code until you find the offending line. Then you know what needs to be ficed.

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.