Search code examples
sqlcheckboxvbscripthta

Update search filter with checkbox, VBScript asp


I have this dynamically search script made in a HTA showing all my notes.

I want to add a dynamic filter, based on two checkboxes that filters my SQL string in types: A, U and both (A or U).

When the script loads it runs perfectly and shows all notes with both types (A or U). But when I click the checkboxes I get an error saying: "Object doesn't support property or method" (translated from my language).

The script is fairly simple I think, but I cannot see the problem. The script searchdata is run dynamically through another script count2 (onkeyup) . I wish the same thing for the checkboxes, so when the checkboxes are ticked, the corresponding results are shown immediately.

Hope I have made myself clear and thanks!

VBScript containing the search filter

sub searchdata
        If acheck.Checked = True AND ucheck.Checked = False Then
        Chkboxval = "A"
        End If
        If acheck.Checked = False AND ucheck.Checked = True Then
        Chkboxval = "U"
        End If
        If acheck.Checked = True AND ucheck.Checked = True Then
        Chkboxval = "U' OR Type='A"
        End If
        If acheck.Checked = False AND ucheck.Checked = False Then
        MsgBox ("Select a filter")
        End If
        SQL_query = "SELECT * FROM arbejde WHERE Title LIKE '%"& txtsrch.value &"%' AND Type='" & Chkboxval & "' ORDER BY Title"
        Set rsData = conn.Execute(SQL_query)
        strHTML2 = strHTML2 & "<table class='detail' cellpadding='0' cellspacing='0' id='detail' border=0 width='97%'><col style='width: 60%;'><col style='width: 31%;'><col style='width: 9%;'><thead><tr><th colspan='4' align='left'></th></tr></thead>"
        If rsData.EOF = True Then
        strHTML2 = strHTML2 & "<span style='color: red'>Ingen resultater!</span><br><a onClick='addNotat()' style='cursor: hand'>Klik her for at oprette et nyt notat</a>"
        End If
        Do Until rsData.EOF = True
        If (rsData("Length") <> "") Then
        infopic = "info-on"
        infolink = "onclick=window.open('" & rsData("Length") & "')"
        ELSE
        infopic = "info-off"
        infolink = ""
        End IF
        strHTML2 = strHTML2 & "<tbody id='bodytext'><tr class='parent' id='trparent' style='font-weight: bold;'><td id='title' height='21'>" & rsData("Title") & "</td><td id='kategori'>" & rsData("Cat") & " (" & rsData("Type") & ")</td><td align='right' id='tools'><img src='images/icons/"& infopic & ".png' width='13' height='13' title='Gå til forretningsgangen' "& infolink & "> <img src='images/icons/edit1.png' width='13' height='13' title='Rediger' onclick='editUser("& rsData("ID") &")' language='vbscript'> <img src='images/icons/slet1.png' width='13' height='13' onclick='deleteUser("& rsData("ID") &")' title='Slet' language='vbscript'>&nbsp;</td></tr><tr class='child'><td colspan='5' id='notat' height='21'>" & rsData("Notes") & "</td></tr></tbody>"
        rsData.moveNext ' go to next record
        Loop
        strHTML2 = strHTML2 & "</table>"
        searchIT.innerHTML = strHTML2
    end sub

Checkboxes:

<input type="checkbox" name="acheck" onclick="searchdata" id="acheck" checked>
<input type="checkbox" name="ucheck" onclick="searchdata" id="ucheck" checked>

Search input:

<input language="vbscript" onload="searchdata" onkeyup="count2" name="txtsrch" id="searchbar" width="15%" tabindex="0" size="35" type="text">

Solution

  • Figured it out myself. Apparently the function searchdata has to be called like searchdata(). This solved this problem but brought other problems, which I now have to face :-) Thanks to Smandoli for the suggestions.

    Before

    <input type="checkbox" name="acheck" onclick="searchdata" id="acheck" checked>
    

    Solution

    <input type="checkbox" name="acheck" onclick="searchdata()" id="acheck" checked>