Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

onchange event error

I get the following error:
SCRIPT5007: The value of the property 'selectQry' is null or undefined, not a Function object
Here's the site: http://isaac.issharepoint.com/demo/pages/iceCreamTruckTracker.aspx

Here's the code if you can't get to the site:

<script>

		<select id="qry" onchange="selectQry()">
		   <option value="State">State</option>
		   <option value="Town Name">Town Name</option>
		   <option value="County Name">County Name</option>
		</select>

$(document).ready(function() { 

//onchange event will trigger getArrayCount() method


	function selectQry(list) {
	var qryVal = list.options[list.selectedIndex].value;
	console.log("Selected selection: "+qryVal);
	
}
//Create name space so their will be no collisions if application grows
	var iceCreamApp = {};
	iceCreamApp.Truck = new Array();
	
	//Load data from list into array right away
	(function() {
		//IIFE() Imediately Invoked Function
		var url = "http://isaac.issharepoint.com/demo/_vti_bin/listdata.svc/IceCreamTrucks?$select=State,TownName,CountyName,IceCreamTrucks";
		$.ajax({
			url:url,
			type:"GET",
			dataType:"json",
			headers: {
                "accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
			success: function(data) {
			//console.log(data.d);
				success(data);
			},
			error: function(data) {
				//failure(data);
				//console.log("ERROR");
			}
		})
			
		function success(data)
		{
			var iceCreamTrucks = data.d.results;
				for(var i = 0; i<iceCreamTrucks.length; i++)
				{
					iceCreamApp.Truck.push(new ICIItem({State:iceCreamTrucks[i].State,
					                           TownName:iceCreamTrucks[i].TownName,
											   CountyName:iceCreamTrucks[i].CountyName,
											   TruckCnt:iceCreamTrucks[i].IceCreamTrucks}));
				}
		}
	}());	
})


function ICIItem(params)
{
	this.TruckCnt = params.TruckCnt;
	if (this.TruckCnt > 5)
	{
		//do something
	}	
	this.State = params.State;
	this.TownName = params.TownName;
	this.CountyName = params.CountyName;
};
ICIItem.prototype.getArrayCount = function(cntType)
{
//Build array number of trucks based on town, state or county. Will be passed in as "cntType"

//pass array to function that will use jqplot
}
		$.each(ticketArray, function (index, value) {			
        		myData.push([ticketArray[index].TicketType, ticketArray[index].Count]);	
 		});
		
	
</script>

Open in new window

Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

The cause of the error is that you have 2 sets of <html><head></head><body></body></html> so the .js file linked in the 2nd set is not recognized by your browser.

BTW, reading your source from "View Source" is really painful.  Have you ever considered cleaning it up?  By cleaning it up I guess you'd have already found such issue.
Avatar of Isaac

ASKER

Most of the code you saw was generated by SharePoint and was not completely my code but thanks for the suggestion.
Avatar of Isaac

ASKER

Can't figure out what the issue is
<script type="text/javascript" src="http://isaac.issharepoint.com/demo/JavaScriptCode/TesticeCreamTrucks.js"></script>

<table>
	<tr>
		<td colspan="2"></td>
	</tr>
	<tr>
		<td colspan="2">
		<select id="qry" onchange="selectQry()">
		   <option value="State">State
		   <option value="Town Name">Town Name
		   <option value="County Name">County Name
		</select>
		</td>
	</tr>	
	<tr>
		<td></td>
		<td></td>
	</tr>
</table>

Open in new window



TesticeCreamTrucks.js
<script type="text/javascript">
$(document).ready(function() { 
alert("HELLO");

	
})

function selectQry()
{
   alert("HELLO WORLD");
}
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Isaac

ASKER

Oh my Gosh!
Thank you so much.  I can't believe I overlooked #1.  That was the problem.
You're welcome.  Glad that I am able to help.  Thanks for the points.