1

当我点击按钮 EDIT and Report... 我不断收到一个错误,上面写着 Object required: '[string: "(null)"]' at line 227 char 1... 不太确定出了什么问题.. 我找不到错误..任何输入表示赞赏

<html>
    <head>
    <script language = "vbscript">
    <!--

    checker = 0 
    selected_val = 1

    Dim radio_select

    function onLoad()
    dim radio_array
    set radio_array = document.getElementsByName("RadioBox")    
    for i = 0 to radio_array.Length - 1
        if radio_array.checked then
            radio_select = radio_array(i).value
            'break
        end if
    next

    end function

    function isValid()

    'Checkbox Loop

    dim checkbox_array
    set checkbox_array = document.getElementsByName("checklist")

    for i = 0 to checkbox_array.Length -1
        if checkbox_array(i).checked then
            checker = true
            'break
        end if
    next

    if checker = false then
        alert("You must check at least one checkbox")
        'break
    end if  


    'SelectMenu Loop

    dim menu_array
    set menu_array = document.getElementById("parts")
    if menu_array.selectedIndex = 0 then
        alert ("Please choose an item from the dropdownlist")
    end if

    'Text Box Editing

    dim text_val
    dim first_string
    dim first_length
    set text_val = document.alice.mybox.value
    set first_string = text_val
    set first_length = cstr(Len(text_val))

    text_val = replace(text_val,"/", "")
    text_val = replace(text_val,"\", "")
    text_val = replace(text_val,"*", "")

    dim second_string
    dim second_length
    set second_string = text_string
    set second_length = cstr(Len(text_val))

    'Text Area

    dim emptybox 
    dim original
    dim originaltwo
    set emptybox = document.alice.textarea.value
    set original = emptybox
    set originaltwo = cstr(Len(emptybox))

    emptybox = replace(emptybox, " ", "+")
    emptybox = replace(emptybox, CHR(13), "+")
    emptybox = replace(emptybox, CHR(10), "+")

    dim new_string
    dim new_length
    set new_string = emptybox
    set new_length = cstr(Len(emptybox))

    end function

    function reporting()

    'Reporting

    'if checker = 1 AND selected_val = 1 then

    if validate() = false then
        exit function
    end if

    dim output : output= ""
    output = output & "<html><body>"
    output = output & "<b><center><h1>Assignment 2 Report</h1></center></b>"
    output = output & "<p>"
    output = output & "<b>Radio Button Information</b>"
    output = output & "<p>"

    dim num
    dim input_select
    set num = document.getElementsByName("RadioBox")
    set input_select = ""

    for i = 0 to num.Length - 1

    output = output & (i+1) & ". Name = " & num(i).name & " Value = " & num(i).value & "<p>"

        if num(i).checked then
            input_select = num(i).value
        end if

    next

    output = output & "<p>"
    output = output & "Initial Radio Button Selection:  " & radio_select & "<br>"
    output = output & "User Radio Button Selection:   " & input_select & "<p>"

    output = output & "<b>Checkbox Information</b><p>"

    dim checkbox_array
    dim user_checks
    set checkbox_array = document.getElementsByName("checklist")
    set user_checks = ""

    for i = 0 to checkbox_array.length

    output = output & " " & (i+1) & "." & checkbox_array(i).value & " "

        if checkbox_array(i).checked then
            user_checks = user_checks & checkbox_array(i).value & " "
        end if
    next

    output = output & "<p>"
    output = output & "User Checkbox Selection:   " & user_checks &"<p>"

    output = output & "<b>Select Box Information</b><p>"
    //
    dim box_choice

    set box_choice = document.getElementById("parts")


    for i = 0 to 5
        output = output & (i + 1) & ". Name = " & box_choice.options(i).text & " Value = "& box_choice.options(i).value &"<br>"
    next

    output = output & "<p>"
    output = output & "Initial Select Box Selection:  " & box_choice(0).text+" , " & box_choice(0).value & "<br>"
    output = output & "User Select Box Selection:   " & box_choice.options(box_choice.selectedIndex).text & ", " & box_choice.options(box_choice.selectedIndex).value & "<p>"

    dim text_info
    set text_info = document.getElementsByName("mybox")

    output = output & "<b>Textbox Information</b><p>"
    output = output & "Text Box Name: " & document.alice.mybox.name & "<br>"
    output = output & "User's Original Entry:" & first_string+" & Length:" & first_length & "<br>"
    output = output & "User's Updated Entry:" & second_string & " & Length:" & second_length & "<p>"

    dim emptybox_info
    set emptybox_info = document.getElementsByName("textarea")

    output = output & "<b>Textarea Information</b><p>"
    output = output & "Text Area Name: " & document.alice.textarea.name & "<br>"
    output = output & "User's Original Entry:" & original & "& Length:" & originaltwo & "<br>"
    output = output & "User's Updated Entry:" & new_string & "& Length:" & new_length & "<br>" 

    output = output & "</body></html>"

    document.open
    document.clear
    document.write(output)
    document.close

    end function

    </script>
    </head>
    <body>
    <form name="alice">
    <center><h1>TP Assignment 2</h1></center>
    <p>
    Choose a Color:
    <br>
    Red <input type="radio" Name="RadioBox"  value="Red" checked><br>
    Yellow<input type="radio" Name="RadioBox" value="Yellow"><br>
    Blue<input type="radio" Name="RadioBox" value="Blue"><br>
    Green<input type="radio" Name="RadioBox" value="Green"><br>
    Orange<input type="radio" Name="RadioBox" value="Orange"><br>
    Purple<input type="radio" Name="RadioBox" value="Purple"><br>
    <p>
    Choose Your Musical Instrument:
    <br>
    Piano <input id="checkbox_first" type="checkbox" name="checklist" value="Piano" title="first">
    Violin <input id="checkbox_second" type="checkbox" name="checklist" value="Violin" title="second">
    Guitar <input id="checkbox_second" type="checkbox" name="checklist" value="Guitar" title="third">
    Drums <input id="checkbox_second" type="checkbox" name="checklist" value="Drums" title="fourth">
    <p>
    Select a Car Part:
    <br>
    <select name="part" id="parts">
    <option value="00" selected>Default</option>
    <option value="11" >Intake Manifold</option>
    <option value="12" >Catalytic Converter</option>
    <option value="13" >Exhaust Manifold</option>
    <option value="14" >Alternator</option>
    </select>
    <p>
    What is your favorite car?
    <br>
    <input type="text" name="mybox" size="20" maxlength="30" value="">
    <p>

    <p>
    What is your favorite memory?
    <br>
    <textarea rows="5" cols="40" name="textarea" value="default value">Default Value</textarea>
    <p>

    <input type="button"  value="EDIT and REPORT" onclick="isValid()">
    <p>
    </form>
    </body>
    </html>
4

1 回答 1

3

问题的一个原因:你有很多行,比如

set first_length = cstr(Len(text_val))

您在哪里使用Set- 仅用于对象 - 将普通/非对象值分配给变量。

于 2013-04-27T07:48:19.573 回答