Morning All!! I am still new to coding and learning very fast (will be teaching computer science this fall). I am creating an app for a class I am taking and I need help because I am lost!!
I have it set up that are searching colleges that are either under or over $25,000 a year in tuition and I have a data set where I have 3 columns (college, price, students). I am using a drop down to select the college and I want the other 2 columns to auto populate in the text box areas but I have no clue what the coding is. I have spend hours looking online to figure out how and I am just missing something!! Any help would be appreciated!!
Here is what I have:
readRecords(“under25k”, {}, function(records) {
var college_list = ;
for (var i=0; i < records.length; i++) {
appendItem(college_list, records[i].college);
}
setProperty(“dropdownU”, “options”, college_list)
});
readRecords(“over25k”, {}, function(records) {
var college_list = ;
for (var i=0; i < records.length; i++) {
appendItem(college_list, records[i].college);
}
setProperty(“dropdownO”, “options”, college_list)
});
I have this as well but I know it is not correct because I have changed it a 1,000 times!! lol
onEvent(“dropdownU”,“change”, function(event){
readRecords(“under25K”, {name:getProperty(“dropdownU”,“text”)}, function(event){
var price_list = ;
for (var i=0; i < records.length; i++) {
appendItem(price_list, records[i].price);
}
setProperty(“price1”,“text”, price_list)
});
HELP!!
here is my app:
I have an immediate interest in what you are trying to do. I will play with a copy of your code and get back to you here when I know more … Can you paste an example .csv of your data table(s) – the data tables do not come with a remix. … Okay, give this a try: https://studio.code.org/projects/applab/Av27xl6SQbGRp4Foamv6ZUiorUxz8OK9scGJYCh7_kg
This should be the only place I made changes:
onEvent(“dropdownU”,“change”, function(event){
var selectedText = getProperty(“dropdownU”,“text”);
//console.log("onEvent dropdownU, selected text is "+selectedText);
readRecords(“under25k”, {college:selectedText}, function(record){
if (record.length > 0) { // length should be one (of type object)
//console.log("onEvent dropdownU, returned record length is "+record.length);
//console.log("onEvent dropdownU, record.price = "+record[0].price);
//console.log("onEvent dropdownU, record.college = "+record[0].college);
//console.log("onEvent dropdownU, record.students = "+record[0].students);
//console.log("onEvent dropdownU, record = "+record[0]);
// retrieve price entry for this record
var textPrice = “$”+record[0].price;
// set the text field on the applicable UI element
setText(“price1”,textPrice);
var textStudents = record[0].students;
setText("numbers1",textStudents)
}
else {
console.log("onEvent dropdownU, returned records length is "+record.length);
}
}); // end of function(record)
}); // end of function(event)
Yes and here are some of the data:
under 25,000
id |
college |
price |
students |
|
Select A College |
|
|
1 |
Ashland University |
20,392 |
3,716 |
2 |
Binghamton University–SUNY |
22,164 |
13,491 |
3 |
Bowling Green State University |
18,332 |
14,334 |
4 |
Brigham Young University–Provo |
5,300 |
30,221 |
5 |
California State University–Fresno |
17,209 |
21,482 |
over 25,000
id |
college |
price |
students |
|
Select A College |
|
|
1 |
Adelphi University |
$34,034 |
4,852 |
2 |
American University |
$44,853 |
7,909 |
3 |
Andrews University |
$27,684 |
1,733 |
4 |
Arizona State University–Tempe |
$25,458 |
41,828 |
5 |
Auburn University |
$28,840 |
21,786 |
Thanks!!