Selected option is not updated even after making the necessary changes











up vote
1
down vote

favorite












I have a semester list dropdown that when changed (i.e. onChange) should call the following function that updates the list of semesters with respect to the newly selected semester:



function updatesemesterlist() {
var semesterlist = document.getElementById("semesterdropdown")
var updatedsemester = semesterlist.value

while(semesterlist.firstChild) {
semesterlist.removeChild(semesterlist.firstChild)
}

semesterparts = updatedsemester.split(" ")
var season = semesterparts[0]
var year = semesterparts[1]

if (season == "Fall") {
var ny = parseInt(year, 10)
ny += 1
nextyear = ny.toString()

var py = parseInt(year, 10)
py -= 1
prevyear = py.toString()

addnewoption(semesterlist, "Fall" + " " + nextyear)
addnewoption(semesterlist, "Spring" + " " + nextyear)
addnewoption(semesterlist, updatedsemester)
addnewoption(semesterlist, "Spring" + " " + year)
addnewoption(semesterlist, "Fall" + " " + prevyear)
}
else {
var ny = parseInt(year, 10)
ny += 1
nextyear = ny.toString()

var py = parseInt(year, 10)
py -= 1
prevyear = py.toString()

addnewoption(semesterlist, "Spring" + " " + nextyear)
addnewoption(semesterlist, "Fall" + " " + year)
addnewoption(semesterlist, updatedsemester)
addnewoption(semesterlist, "Fall" + " " + prevyear)
addnewoption(semesterlist, "Spring" + " " + prevyear)
}

semesterlist.value = updatedsemester
retrieveclasses(updatedsemester)
}


The function above the calls the retrieveclasses(semester) function, which updates the list of options selected based on data stored in a map structure:



function retrieveclasses(semester) {
classes = semestertoclasses.get(semester)

var table_body = document.getElementById("table of classes").children[1]
while(table_body.firstChild){
table_body.removeChild(table_body.firstChild)
}

console.log(classes)
if(classes != undefined ){
var count = 1
for(var key of Array.from(classes.keys())){
addclass()
var course = document.getElementById("course-select" + (count.toString()))
course.value = key
course.options[course.options.selectedIndex].selected = true
var requirement = document.getElementById("requirement-select" + (count.toString()))
requirement.value = classes.get(key)
requirement.options[requirement.options.selectedIndex].selected = true
count++
}
}

}


For reference, the map is updated with the following function:



function saveclasses(){
var table_body = document.getElementById("table of classes").children[1]
var num_classes = table_body.childElementCount
var semester = document.getElementById("semesterdropdown").value

var courses = table_body.children

var classtorequirement = new Map();

for (var i = 0; i < courses.length; i++){
var data = courses[i].children
classtorequirement.set(data[0].firstChild.children[3].innerHTML,
data[1].firstChild.children[3].innerHTML)
}

semestertoclasses.set(semester, classtorequirement)

}


Where semestertoclasses is initially defined at the top of my javascript file:



var semestertoclasses = new Map();


Now suppose I update the classes I want to take in the 'Fall 2018' semester and then save those courses with the 'Save Courses' button:
Fall 2018 Courses



Then I go to a new semester:
Spring 2019



When I go back to 'Fall 2018', the courses should be updated with the ones that I initially saved (CS 2800 and MATH 2940, as well as the corresponding requirements they fulfill). However, this is not the case:
After going back to Fall 2018



I debugged this issue by ensuring that the selected indices were correct (i.e. by logging options.selectedIndex to the console), and it was indeed correct. But the classes are not updated.



I'm having a hard time exactly figuring out what could cause this issue to occur. I appreciate any suggestions, thank you!










share|improve this question
























  • Can you add your code to a jsFiddle?
    – Simsteve7
    Nov 9 at 22:33










  • jsfiddle.net/8sfpzL6c
    – azdev
    Nov 10 at 0:44










  • @Simsteve7 Please do not request code on external code sites. StackOverflow has snippet functionality which is what is required to use unless SO snippet functionality is not sufficient.
    – connexo
    Nov 10 at 22:20















up vote
1
down vote

favorite












I have a semester list dropdown that when changed (i.e. onChange) should call the following function that updates the list of semesters with respect to the newly selected semester:



function updatesemesterlist() {
var semesterlist = document.getElementById("semesterdropdown")
var updatedsemester = semesterlist.value

while(semesterlist.firstChild) {
semesterlist.removeChild(semesterlist.firstChild)
}

semesterparts = updatedsemester.split(" ")
var season = semesterparts[0]
var year = semesterparts[1]

if (season == "Fall") {
var ny = parseInt(year, 10)
ny += 1
nextyear = ny.toString()

var py = parseInt(year, 10)
py -= 1
prevyear = py.toString()

addnewoption(semesterlist, "Fall" + " " + nextyear)
addnewoption(semesterlist, "Spring" + " " + nextyear)
addnewoption(semesterlist, updatedsemester)
addnewoption(semesterlist, "Spring" + " " + year)
addnewoption(semesterlist, "Fall" + " " + prevyear)
}
else {
var ny = parseInt(year, 10)
ny += 1
nextyear = ny.toString()

var py = parseInt(year, 10)
py -= 1
prevyear = py.toString()

addnewoption(semesterlist, "Spring" + " " + nextyear)
addnewoption(semesterlist, "Fall" + " " + year)
addnewoption(semesterlist, updatedsemester)
addnewoption(semesterlist, "Fall" + " " + prevyear)
addnewoption(semesterlist, "Spring" + " " + prevyear)
}

semesterlist.value = updatedsemester
retrieveclasses(updatedsemester)
}


The function above the calls the retrieveclasses(semester) function, which updates the list of options selected based on data stored in a map structure:



function retrieveclasses(semester) {
classes = semestertoclasses.get(semester)

var table_body = document.getElementById("table of classes").children[1]
while(table_body.firstChild){
table_body.removeChild(table_body.firstChild)
}

console.log(classes)
if(classes != undefined ){
var count = 1
for(var key of Array.from(classes.keys())){
addclass()
var course = document.getElementById("course-select" + (count.toString()))
course.value = key
course.options[course.options.selectedIndex].selected = true
var requirement = document.getElementById("requirement-select" + (count.toString()))
requirement.value = classes.get(key)
requirement.options[requirement.options.selectedIndex].selected = true
count++
}
}

}


For reference, the map is updated with the following function:



function saveclasses(){
var table_body = document.getElementById("table of classes").children[1]
var num_classes = table_body.childElementCount
var semester = document.getElementById("semesterdropdown").value

var courses = table_body.children

var classtorequirement = new Map();

for (var i = 0; i < courses.length; i++){
var data = courses[i].children
classtorequirement.set(data[0].firstChild.children[3].innerHTML,
data[1].firstChild.children[3].innerHTML)
}

semestertoclasses.set(semester, classtorequirement)

}


Where semestertoclasses is initially defined at the top of my javascript file:



var semestertoclasses = new Map();


Now suppose I update the classes I want to take in the 'Fall 2018' semester and then save those courses with the 'Save Courses' button:
Fall 2018 Courses



Then I go to a new semester:
Spring 2019



When I go back to 'Fall 2018', the courses should be updated with the ones that I initially saved (CS 2800 and MATH 2940, as well as the corresponding requirements they fulfill). However, this is not the case:
After going back to Fall 2018



I debugged this issue by ensuring that the selected indices were correct (i.e. by logging options.selectedIndex to the console), and it was indeed correct. But the classes are not updated.



I'm having a hard time exactly figuring out what could cause this issue to occur. I appreciate any suggestions, thank you!










share|improve this question
























  • Can you add your code to a jsFiddle?
    – Simsteve7
    Nov 9 at 22:33










  • jsfiddle.net/8sfpzL6c
    – azdev
    Nov 10 at 0:44










  • @Simsteve7 Please do not request code on external code sites. StackOverflow has snippet functionality which is what is required to use unless SO snippet functionality is not sufficient.
    – connexo
    Nov 10 at 22:20













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a semester list dropdown that when changed (i.e. onChange) should call the following function that updates the list of semesters with respect to the newly selected semester:



function updatesemesterlist() {
var semesterlist = document.getElementById("semesterdropdown")
var updatedsemester = semesterlist.value

while(semesterlist.firstChild) {
semesterlist.removeChild(semesterlist.firstChild)
}

semesterparts = updatedsemester.split(" ")
var season = semesterparts[0]
var year = semesterparts[1]

if (season == "Fall") {
var ny = parseInt(year, 10)
ny += 1
nextyear = ny.toString()

var py = parseInt(year, 10)
py -= 1
prevyear = py.toString()

addnewoption(semesterlist, "Fall" + " " + nextyear)
addnewoption(semesterlist, "Spring" + " " + nextyear)
addnewoption(semesterlist, updatedsemester)
addnewoption(semesterlist, "Spring" + " " + year)
addnewoption(semesterlist, "Fall" + " " + prevyear)
}
else {
var ny = parseInt(year, 10)
ny += 1
nextyear = ny.toString()

var py = parseInt(year, 10)
py -= 1
prevyear = py.toString()

addnewoption(semesterlist, "Spring" + " " + nextyear)
addnewoption(semesterlist, "Fall" + " " + year)
addnewoption(semesterlist, updatedsemester)
addnewoption(semesterlist, "Fall" + " " + prevyear)
addnewoption(semesterlist, "Spring" + " " + prevyear)
}

semesterlist.value = updatedsemester
retrieveclasses(updatedsemester)
}


The function above the calls the retrieveclasses(semester) function, which updates the list of options selected based on data stored in a map structure:



function retrieveclasses(semester) {
classes = semestertoclasses.get(semester)

var table_body = document.getElementById("table of classes").children[1]
while(table_body.firstChild){
table_body.removeChild(table_body.firstChild)
}

console.log(classes)
if(classes != undefined ){
var count = 1
for(var key of Array.from(classes.keys())){
addclass()
var course = document.getElementById("course-select" + (count.toString()))
course.value = key
course.options[course.options.selectedIndex].selected = true
var requirement = document.getElementById("requirement-select" + (count.toString()))
requirement.value = classes.get(key)
requirement.options[requirement.options.selectedIndex].selected = true
count++
}
}

}


For reference, the map is updated with the following function:



function saveclasses(){
var table_body = document.getElementById("table of classes").children[1]
var num_classes = table_body.childElementCount
var semester = document.getElementById("semesterdropdown").value

var courses = table_body.children

var classtorequirement = new Map();

for (var i = 0; i < courses.length; i++){
var data = courses[i].children
classtorequirement.set(data[0].firstChild.children[3].innerHTML,
data[1].firstChild.children[3].innerHTML)
}

semestertoclasses.set(semester, classtorequirement)

}


Where semestertoclasses is initially defined at the top of my javascript file:



var semestertoclasses = new Map();


Now suppose I update the classes I want to take in the 'Fall 2018' semester and then save those courses with the 'Save Courses' button:
Fall 2018 Courses



Then I go to a new semester:
Spring 2019



When I go back to 'Fall 2018', the courses should be updated with the ones that I initially saved (CS 2800 and MATH 2940, as well as the corresponding requirements they fulfill). However, this is not the case:
After going back to Fall 2018



I debugged this issue by ensuring that the selected indices were correct (i.e. by logging options.selectedIndex to the console), and it was indeed correct. But the classes are not updated.



I'm having a hard time exactly figuring out what could cause this issue to occur. I appreciate any suggestions, thank you!










share|improve this question















I have a semester list dropdown that when changed (i.e. onChange) should call the following function that updates the list of semesters with respect to the newly selected semester:



function updatesemesterlist() {
var semesterlist = document.getElementById("semesterdropdown")
var updatedsemester = semesterlist.value

while(semesterlist.firstChild) {
semesterlist.removeChild(semesterlist.firstChild)
}

semesterparts = updatedsemester.split(" ")
var season = semesterparts[0]
var year = semesterparts[1]

if (season == "Fall") {
var ny = parseInt(year, 10)
ny += 1
nextyear = ny.toString()

var py = parseInt(year, 10)
py -= 1
prevyear = py.toString()

addnewoption(semesterlist, "Fall" + " " + nextyear)
addnewoption(semesterlist, "Spring" + " " + nextyear)
addnewoption(semesterlist, updatedsemester)
addnewoption(semesterlist, "Spring" + " " + year)
addnewoption(semesterlist, "Fall" + " " + prevyear)
}
else {
var ny = parseInt(year, 10)
ny += 1
nextyear = ny.toString()

var py = parseInt(year, 10)
py -= 1
prevyear = py.toString()

addnewoption(semesterlist, "Spring" + " " + nextyear)
addnewoption(semesterlist, "Fall" + " " + year)
addnewoption(semesterlist, updatedsemester)
addnewoption(semesterlist, "Fall" + " " + prevyear)
addnewoption(semesterlist, "Spring" + " " + prevyear)
}

semesterlist.value = updatedsemester
retrieveclasses(updatedsemester)
}


The function above the calls the retrieveclasses(semester) function, which updates the list of options selected based on data stored in a map structure:



function retrieveclasses(semester) {
classes = semestertoclasses.get(semester)

var table_body = document.getElementById("table of classes").children[1]
while(table_body.firstChild){
table_body.removeChild(table_body.firstChild)
}

console.log(classes)
if(classes != undefined ){
var count = 1
for(var key of Array.from(classes.keys())){
addclass()
var course = document.getElementById("course-select" + (count.toString()))
course.value = key
course.options[course.options.selectedIndex].selected = true
var requirement = document.getElementById("requirement-select" + (count.toString()))
requirement.value = classes.get(key)
requirement.options[requirement.options.selectedIndex].selected = true
count++
}
}

}


For reference, the map is updated with the following function:



function saveclasses(){
var table_body = document.getElementById("table of classes").children[1]
var num_classes = table_body.childElementCount
var semester = document.getElementById("semesterdropdown").value

var courses = table_body.children

var classtorequirement = new Map();

for (var i = 0; i < courses.length; i++){
var data = courses[i].children
classtorequirement.set(data[0].firstChild.children[3].innerHTML,
data[1].firstChild.children[3].innerHTML)
}

semestertoclasses.set(semester, classtorequirement)

}


Where semestertoclasses is initially defined at the top of my javascript file:



var semestertoclasses = new Map();


Now suppose I update the classes I want to take in the 'Fall 2018' semester and then save those courses with the 'Save Courses' button:
Fall 2018 Courses



Then I go to a new semester:
Spring 2019



When I go back to 'Fall 2018', the courses should be updated with the ones that I initially saved (CS 2800 and MATH 2940, as well as the corresponding requirements they fulfill). However, this is not the case:
After going back to Fall 2018



I debugged this issue by ensuring that the selected indices were correct (i.e. by logging options.selectedIndex to the console), and it was indeed correct. But the classes are not updated.



I'm having a hard time exactly figuring out what could cause this issue to occur. I appreciate any suggestions, thank you!







javascript html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 22:16









marc_s

565k12610921244




565k12610921244










asked Nov 9 at 22:16









azdev

61




61












  • Can you add your code to a jsFiddle?
    – Simsteve7
    Nov 9 at 22:33










  • jsfiddle.net/8sfpzL6c
    – azdev
    Nov 10 at 0:44










  • @Simsteve7 Please do not request code on external code sites. StackOverflow has snippet functionality which is what is required to use unless SO snippet functionality is not sufficient.
    – connexo
    Nov 10 at 22:20


















  • Can you add your code to a jsFiddle?
    – Simsteve7
    Nov 9 at 22:33










  • jsfiddle.net/8sfpzL6c
    – azdev
    Nov 10 at 0:44










  • @Simsteve7 Please do not request code on external code sites. StackOverflow has snippet functionality which is what is required to use unless SO snippet functionality is not sufficient.
    – connexo
    Nov 10 at 22:20
















Can you add your code to a jsFiddle?
– Simsteve7
Nov 9 at 22:33




Can you add your code to a jsFiddle?
– Simsteve7
Nov 9 at 22:33












jsfiddle.net/8sfpzL6c
– azdev
Nov 10 at 0:44




jsfiddle.net/8sfpzL6c
– azdev
Nov 10 at 0:44












@Simsteve7 Please do not request code on external code sites. StackOverflow has snippet functionality which is what is required to use unless SO snippet functionality is not sufficient.
– connexo
Nov 10 at 22:20




@Simsteve7 Please do not request code on external code sites. StackOverflow has snippet functionality which is what is required to use unless SO snippet functionality is not sufficient.
– connexo
Nov 10 at 22:20

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233963%2fselected-option-is-not-updated-even-after-making-the-necessary-changes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233963%2fselected-option-is-not-updated-even-after-making-the-necessary-changes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python