SCRIPT5007 IE9及更低版本中的Javascript错误

时间:2014-08-22 09:21:41

标签: javascript html internet-explorer

我遇到了这个让我发疯的问题。我已经使这个Javascript函数在每个浏览器中都有效,只在IE9和更低版本中我得到了这个错误。

这是我在荷兰语中遇到的错误。

SCRIPT5007:Kan de eigenschap value van een niet-gedefinieerde verwijzing of een verwijzing naar een lege waarde niet instellen

这是翻译版本:

SCRIPT5007:未设置未定义引用的value属性或未设置空值的引用。

这是我的Javascript功能:

        function Calculate()
    {
        var l = document.getElementById('aantal-caps').value;
        var l2 = document.getElementById('aantal-paraplu').value;
        var l3 = document.getElementById('aantal-blue-tooth').value;
        var l4 = document.getElementById('aantal-backpack').value;
        var result = l * 12 + l2 * 12 + l3 * 20 + l4 * 50;
        document.getElementById('totaal').innerHTML = result;
        document.aanvraag.totaal.value = result; 
        var punten = 345; // Aantal spaarpunten van de klant. Die kan jij hier inschieten.
        var bereken = punten - result;
        if(bereken < 0)
            {
                bereken = '<span style="color:#ff0000"><b>Saldo niet toereikend</b></span>';
                document.getElementById("Submitform").disabled = true; 
            } else 
            {
                bereken = punten - result;
                document.getElementById("Submitform").disabled = false; 
            }
        document.getElementById('punten-aantal').innerHTML = bereken;
        document.getElementById('uwpunten').innerHTML = punten;

    }
    window.onload=Calculate;

这是我的HTML表格,其中显示了所选的javascript值:

<table style="float:left; width:350px; height:247px;">
<tr>
    <th height="15px">Spaarpunten</th>
</tr>
<tr>
    <td>Uw aantal spaarpunten : </td>
    <td><strong style="font-size:14px"><span id="uwpunten" style="color:#0acb00;">0<input type="hidden" name="uwpunten" id="uwpunten" value="" /></span></strong></td>
</tr>
<tr>
    <td>De huidige selectie kost u : </td>
    <td><strong style="font-size:14px"><span id="totaal" style="color:#F00;">0<input type="hidden" name="totaal" id="totaal" value="" /></span></strong></td>
</tr>
<tr>
    <td>-------------------------------</td>
    <td>-----</td>
</tr>
<tr>
    <td>U heeft nog : </td>
    <td><strong style="font-size:14px"><span id="punten-aantal" style="color:#0acb00;">0<input type="hidden" name="punten-aantal" id="punten-aantal" value="" /></span></strong></td>
</tr>

这是我的选择形式:

    <table width="700" cellpadding="3" cellspacing="3" style="float:left;">
    <tr>
        <th>Kies een product</th>
    </tr>
    <tr>
        <td><img src="cap.jpg" /></td>
        <td><img src="paraplu.jpg" /></td>
        <td><img src="bandenspeaker.jpg" /></td>
        <td><img src="backpack.jpg" /></td>
    </tr>
    <tr>
        <td><select id="aantal-caps" name="aantal-caps" onChange="Calculate();">
                <option value="0" selected="selected">Kies het aantal</option>
                <option value="1" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "1") {echo "selected='selected'"; } ?>>1</option>
                <option value="2" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "2") {echo "selected='selected'"; } ?>>2</option>
                <option value="3" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "3") {echo "selected='selected'"; } ?>>3</option>
                <option value="4" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "4") {echo "selected='selected'"; } ?>>4</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "5") {echo "selected='selected'"; } ?>>5</option>
                <option value="6" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "6") {echo "selected='selected'"; } ?>>6</option>
                <option value="7" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "7") {echo "selected='selected'"; } ?>>7</option>
                <option value="8" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "8") {echo "selected='selected'"; } ?>>8</option>
                <option value="9" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "9") {echo "selected='selected'"; } ?>>9</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-caps']) == "10") {echo "selected='selected'"; } ?>>10</option>
            </select>
        </td>
        <td><select id="aantal-paraplu" name="aantal-paraplu" onChange="Calculate();">
                <option value="0" selected="selected">Kies het aantal</option>
                <option value="1" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "1") {echo "selected='selected'"; } ?>>1</option>
                <option value="2" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "2") {echo "selected='selected'"; } ?>>2</option>
                <option value="3" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "3") {echo "selected='selected'"; } ?>>3</option>
                <option value="4" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "4") {echo "selected='selected'"; } ?>>4</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "5") {echo "selected='selected'"; } ?>>5</option>
                <option value="6" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "6") {echo "selected='selected'"; } ?>>6</option>
                <option value="7" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "7") {echo "selected='selected'"; } ?>>7</option>
                <option value="8" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "8") {echo "selected='selected'"; } ?>>8</option>
                <option value="9" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "9") {echo "selected='selected'"; } ?>>9</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-paraplu']) == "10") {echo "selected='selected'"; } ?>>10</option>
            </select>
        </td>
        <td><select id="aantal-blue-tooth" name="aantal-blue-tooth" onChange="Calculate();">
                <option value="0" selected="selected">Kies het aantal</option>
                <option value="1" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "1") {echo "selected='selected'"; } ?>>1</option>
                <option value="2" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "2") {echo "selected='selected'"; } ?>>2</option>
                <option value="3" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "3") {echo "selected='selected'"; } ?>>3</option>
                <option value="4" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "4") {echo "selected='selected'"; } ?>>4</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "5") {echo "selected='selected'"; } ?>>5</option>
                <option value="6" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "6") {echo "selected='selected'"; } ?>>6</option>
                <option value="7" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "7") {echo "selected='selected'"; } ?>>7</option>
                <option value="8" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "8") {echo "selected='selected'"; } ?>>8</option>
                <option value="9" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "9") {echo "selected='selected'"; } ?>>9</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-blue-tooth']) == "10") {echo "selected='selected'"; } ?>>10</option>
            </select>
        </td>
        <td><select id="aantal-backpack" name="aantal-backpack" onChange="Calculate();">
                <option value="0" selected="selected">Kies het aantal</option>
                <option value="1" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "1") {echo "selected='selected'"; } ?>>1</option>
                <option value="2" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "2") {echo "selected='selected'"; } ?>>2</option>
                <option value="3" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "3") {echo "selected='selected'"; } ?>>3</option>
                <option value="4" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "4") {echo "selected='selected'"; } ?>>4</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "5") {echo "selected='selected'"; } ?>>5</option>
                <option value="6" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "6") {echo "selected='selected'"; } ?>>6</option>
                <option value="7" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "7") {echo "selected='selected'"; } ?>>7</option>
                <option value="8" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "8") {echo "selected='selected'"; } ?>>8</option>
                <option value="9" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "9") {echo "selected='selected'"; } ?>>9</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-backpack']) == "10") {echo "selected='selected'"; } ?>>10</option>
            </select>
        </td>
    </tr>

    

很抱歉发布了所有代码,但大部分时间最好还是了解我的目标。

此字段:

<td><strong style="font-size:14px"><span id="totaal" style="color:#F00;">0<input type="hidden" name="totaal" id="totaal" value="" /></span></strong></td>

是唯一有效的字段。其他两个字段我在页面加载时得到SCRIPT5007错误,当我在表单中选择另一个字段时。

为什么这只发生在IE9及更低版本?有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:0)

document.aanvraag.totaal.value = result; 

这导致了我的错误