在搜索输出中,有一个下拉框可以更改姓氏的来源。
但是,当您尝试更改选择字段中的值时,出现错误;
Cannot read property 'origin' of null at HTMLSelectElement.onchange
代码在这里;
//functions to parse the querystring
function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; }
}
function queryString(key){
var page = new PageQuery(window.location.search);
return unescape(page.getValue(key));
}
function decode(str) {
return unescape(str.replace(/\+/g, " "));
}
if (queryString("surname")!="" && queryString("surname")!="false"){
document.write ("<h3>Surname</h3>");
document.write (queryString("surname"));
if(queryString("numoforigins") == ""){
document.write ("<br /><br />The name was not found.");
}else{
document.write ("<h3>Origin</h3>");
if (queryString("numoforigins") == "1"){
document.write (queryString("wordorigin"));
}else{
document.write ("<select name='origin' onchange='if (this.form.origin.options[this.form.origin.selectedIndex].value) window.location.href=this.form.origin.options[this.form.origin.selectedIndex].value'>");
document.write ("<option selected>" + queryString("wordorigin") + "</option>");
//loops through all origins and adds to combobox and calls surnameSearch.asp every time the combobox value changes
for(var i=1; i <= parseInt(queryString("numoforigins")); i++){
if (queryString("wordorigin") != queryString("originword" + i)) //ensures no duplicate options put into combobox
document.write("<option value='https://www.hallofnames.com/services/surnameSearch.asp?Licensee=24010&surname=" + queryString("surname") + "&origin=" + queryString("origin" + i) + "'>" + queryString("originword" + i) + "</OPTION>" );
}
document.write ( "</select> (" + queryString("numoforigins") + " origins available)");
}
if(queryString("hisdata")!="" && queryString("hisdata")!="false"){
document.write ( "<h3>History</h3>");
document.write (decode(queryString("hisdata")));
}
if(queryString("motto")!="" && queryString("motto")!="false"){
document.write ("<h3>Motto</h3>");
document.write (decode(queryString("motto")));
}
if(queryString("mottotranslated")!="" && queryString("mottotranslated")!="false"){
document.write ("<h3>Motto Translated</h3>");
document.write (decode(queryString("mottotranslated")));
}
if(queryString("crest")!="" && queryString("crest")!="false"){
document.write ("<h3>Crest</h3>");
document.write (decode(queryString("crest")));
}
if(queryString("coa")!="" && queryString("coa")!="false"){
document.write ("<h3>Coat of Arms</h3>");
document.write (decode(queryString("coa")));
}
}
}
它应该重新加载页面并显示新的原点,但我收到此错误,但不幸的是它没有给出代码行。
详细错误是否有帮助?
Uncaught TypeError: Cannot read property 'origin' of null
at HTMLSelectElement.onchange (search-results?surname=Smith&origin=DU&wordorigin=Dutch&hisdata=Spelling+variations+of+this+family+name+include%3A+Smit%2C+Smitt%2C+Smitte%2C+Smites%2C+Smitts%2C+Smiit%2C+Smiites%2C+Smittes%2C+van+Smit%2C+Smut%2C+Smutts%2C+van+Smutts%2C+Schmit%2C+Schmidt%2C+van+Schmidt+and+many+more.+First+found+in+Holland%2C+where+the+name+became+noted+for+its+many+branches+in+the+region%2C+each+house+acquiring+a+status+and+influence+which+was+envied+by+the+princes+of+the+region.+Some+of+the+first+settlers+of+this+family+name+or+some+of+its+variants+were%3A+Claes+Claesen+Smitt%2C+who+arrived+in++New+York%2C+NY+in+1653%3B+Andries+Smit%2C+who+arrived+in++England+or+America+in+1709%3B+Adam+Schmit%2C+who+arrived+in++England+or+America+in+1709.&motto=&mottoTranslated=&crest=Description+not+available&coa=Blue+with+three+gold+horseshoes.+Two+on+top+and+one+below.&numoforigins=5&origin1=DU&originword1=Dutch&origin2=EN&originword2=English&origin3=GR&originword3=German&origin4=IR&originword4=Irish&origin5=SC&originword5=Scottish:302)
有人可以帮忙吗?