Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

javascript - SCRIPT5007: Unable to get property 'value' of undefined or null reference

I have a html form that appears not to be functional in IE10. when click on go button debugging returns:"SCRIPT5007: Unable to get property 'value' of undefined or null reference" I have added this tag in my html page

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />.

html contains dropdown menu option for frequency in myform.After selecting any option in dropdown i am calling below javascript function.

function chooseFreqMenu(freqValues,freqTexts)
{
    var cf = document.myform;
    var freq1=document.myform.freq.value; // freq1="d"
    alert(freq1);// displaying freq1 value is "d" (ex:selected 'd' in html dropdown)
// checking some condition for freqValues.
    for(var i=4;i<freqValues.length;i++)
            selectStr += '<option value="'+freqValues[i]+'">'+freqTexts[i]+'
';
    }
    selectStr += '</select>';
    // Assinging the selectedStr to innerHTML. After this statement i am getting empty for freq1 value. 
    //Its working fine in IE<10 browsers
    document.all.freqSel.innerHTML = selectStr; 
    alert(freq1); // displaying freq1 value is empty.
}   

Before sending myform to chooseFreqmenu, myform contains freq value="d"(assume i selected 'd' in dropdown) After the above function myform doesn't contain freq value. After the above function passing myform to buildQueryStr.

function buildQueryStr(myform)
{

var freq=myform.freq.value; //Getting an error SCRIPT5007: Unable to get property 'value' of undefined or null reference in this line

//some other fields.

}

How to fix this issue?

Any suggestions?? Thanks in Advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't think IE 10 supports acessing elements with the myform.freq.value syntax anymore.

The standard way of accessing Elements (this is supported in all browsers including IE) is with the document.getElementById function

function buildQueryStr(myform) {

    //var freq=myform.freq.value; //Getting an error SCRIPT5007: Unable to get property 'value' of undefined or null reference in this line
    var freq=document.getElementById("freq").value;

    //some other fields.
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...