Jump to content

Recommended Posts

Posted

I am wondering how to filter results out of a record set. I have to find all of the "unique zip codes" in a record set and than display them. I have a start to the program where it displays all of the zip codes I'm just not sure how to filter out the duplicate so the don't show up. If I can do it as an array I think I know how to do it. I just need a little help in the right direction. Here is what I have so far.

 

function project5Part1() {
   //Constant Variables
   ZERO = 0;

   // Variable Declarations
   var zipCode;
   var output;
   var records;
   var count = ZERO;
   var display = "";

   // Display results
   output = document.getElementById("outputDiv");

   // Open the Zip Code Study Records and make them
   // available to the script
   records = openZipCodeStudyRecordSet();

   while (records.readNextRecord()) {
       zipCode = records.getSampleZipCode();
       count++;
   }

   // Output the results
   output.innerHTML = display + "<br />";
}

Posted

I have went to many of the sites you told me about and have found great information. However I can not find out how to turn a recordset into an array. I know this is very basic, but it's just something I have missed. Here's my new code.

/*
   This is the JavaScript code for 
   "Find Unique Zip Codes" 
   File: /unit5/project/project5Part1.html
*/
function project5Part1() {

   var myArray = new Array();
   var sortedArrayOfStudents;
   var zipCodeRecords;
   var output;
   var arrayOfZipCodes;
   var test = "";

   output = document.getElementById("outputDiv");
   zipCodeRecords = openZipCodeStudyRecordSet();

   while (zipCodeRecords.readNextRecord()) {
   arrayOfZipCodes = zipCodeRecords.getSampleZipCode();
   myArray = arrayOfZipCodes;
   test +=  myArray + "<br />";
   }



   output.innerHTML = test + "<br />"; //will have to fix output
   return false;
}

Posted

I am not very experienced in JavaScript so bare with me If I'm out completely wrong, but as you put the next record in myArray that you later pass into the test variable before you do that check with a if-statement if the current myArray value contain in the test variable.

 

if (check if (not)the current myArray value contain in the test variable) {
test +=  myArray + "<br />";
}

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
×
×
  • Create New...