Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 21, 2011, 01:25 PM   #1
jarv
macrumors newbie
 
Join Date: Jan 2011
dashcode errors in custom JavaScript

hi,

I am getting several error from my javaScript I inserted into my javaScript page in DashCode

Code:
function ajaxFunction(){
	var townRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		townRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			townRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				townRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	townRequest.onreadystatechange = function(){
		if(townRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = townRequest.responseText;
		}
	}
	var name = document.getElementById('name').value;
	var county = document.getElementById('county').value;
	var town = document.getElementById('town').value;
	var queryString = "?name=" + name + "&county=" + county + "&town=" + town;
	townRequest.open("GET", "http://www.mypubspace.com/dashtest/pubs.php" + queryString, true);
	townRequest.send(null); 
}

this all works fine in my page:
http://www.mypubspace.com/dashtest/order.html
jarv is offline   0 Reply With Quote
Old Jan 21, 2011, 02:10 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
What errors are you getting? Be specific.
chown33 is offline   0 Reply With Quote
Old Jan 23, 2011, 06:31 AM   #3
jarv
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Hi,

Here I have a HTML page which uses Ajax to GET data from a PHP page

http://www.mypubspace.com/dashtest/order.html

I would like to use this for an iPhone Application.
here are the steps I have taken

step 1: added JavaScript to my .js page in DashCode
step 2: assigned behaviours to 2 buttons in DashCode
step 3: tested and received error: 'ajaxDisplay' null is not an object

here is my HTML/JS
Code:
<html>
<body>

<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function ajaxFunction(){
	var townRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		townRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			townRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				townRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	townRequest.onreadystatechange = function(){
		if(townRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = townRequest.responseText;
		}
	}
	var name = document.getElementById('name').value;
	var county = document.getElementById('county').value;
	var town = document.getElementById('town').value;
	var queryString = "?name=" + name + "&county=" + county + "&town=" + town;
	//Add the following line
	townRequest.open("GET", "http://www.mypubspace.com/dashtest/townpubs.php" + queryString, true);
	townRequest.send(null);
}

function countyFunction(){
	var countyRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		countyRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			countyRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				countyRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	countyRequest.onreadystatechange = function(){
		if(countyRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = countyRequest.responseText;
		}
	}
	var name = document.getElementById('name').value;
	var county = document.getElementById('county').value;
	var town = document.getElementById('town').value;
	var queryString = "?name=" + name + "&county=" + county + "&town=" + town;
	//Add the following line
	countyRequest.open("GET", "http://www.mypubspace.com/dashtest/countypubs.php" + queryString, true);
	countyRequest.send(null);
}



function townlistFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxTownlist');
			var county = document.getElementById('county').value;
			var town = document.getElementById('town').value;
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "http://www.mypubspace.com/dashtest/town-select.php", true);
	ajaxRequest.send(null); 
}

function countylistFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxCountylist');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "http://www.mypubspace.com/dashtest/county-select.php", true);
	ajaxRequest.send(null); 
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//-->
</script>

<a href="#" onClick="townlistFunction();">show towns list</a>
<a href="#" onClick="countylistFunction();">show counties list</a>
<form name='myForm'>
<div id="ajaxTownlist"></div>
<div id="ajaxCountylist"></div>
<input type='hidden' id='name' />
<input type='hidden' id='county' />
<input type='hidden' id='town' />
</form>
<div id='ajaxDiv'></div>
</body>
</html>
here is one of my PHP pages
Code:
<?php
$dbhost = "xxx";
$dbuser = "xxx";
$dbpass = "xxx";
$dbname = "xxx";
	//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
	//Select Database
mysql_select_db($dbname) or die(mysql_error());
	// Retrieve data from Query String
	var ajaxDisplay = document.getElementById('ajaxDiv');
$town = $_GET['rsTown'];
	// Escape User Input to help prevent SQL Injection

$town = mysql_real_escape_string($town);
//build query
$query = "SELECT DISTINCT rsTown, COUNT(PUBID) As PubCount FROM pubs GROUP BY rsTown  ORDER BY rsTown ASC";
$qry_result = mysql_query($query) or die(mysql_error());

	// Insert a new row in the table for each person returned
		  
$display_string .= "<select name=\"town\" id=\"town\" onChange=\"ajaxFunction();\" class=\"textbox\">\n";
$display_string .= "<option value=\"\">Search by Town...</option>\n";
while($row = mysql_fetch_array($qry_result))
{
    $display_string .= "<option value=\"{$row['rsTown']}\" onclick=\"\">{$row['rsTown']}&nbsp;({$row['PubCount']})</option>\n";
}
$display_string .= "</select>\n";
	
echo $display_string;
?>
I think I need an area to show the data in for the <div id="ajaxDiv"></div>
I really hope someone can help me?!

thanks
jarv is offline   0 Reply With Quote

Reply
MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Tags
ajax, dashcode, javascript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
dashcode help fracksoup Mac Programming 1 Nov 15, 2013 01:10 PM
Javascript Errors. iPhone Safari Won't load websites. predarkness iPhone Tips, Help and Troubleshooting 2 Oct 20, 2013 12:16 PM
How to get Dashcode bb13 Mac Programming 3 Aug 4, 2013 11:39 AM
OS Hangs On Firefox and Thunderbird Javascript Errors steiney MacBook Pro 0 May 8, 2013 08:41 PM
Dashcode; Javascript; Nexus 7 Issue. LazyBrush Web Design and Development 3 Apr 18, 2013 08:07 AM

Forum Jump

All times are GMT -5. The time now is 01:25 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC