2016-03-28 8 views
0

私のVBScriptアプリケーションにSubがあります。検索ボタンをクリックするとページ上に表が表示されますが、window.location.reload()メソッドを使用してページを消去する別のボタンがあります。条件付きで関数を呼び出す

私の問題は、ユーザーが検索ボタンをクリックしてテーブルを作成した後、ユーザーが再度検索ボタンをクリックすると、テーブルに追加のデータが追加されることです。

最初にページをクリアしてから、テーブルを作成する必要があります。 反復があるので、Search(directory) Sub内で単にwindow.location.reload()と呼ぶことはできません。

<p> 
<input name="Clear" type="button" class = "button" value="Clear" OnClick="window.location.reload()"> 
<input name="Search" type="button" class = "buttongo aright" value="Search" OnClick="Search"> 
</p> 

私のVBScriptコードは次のとおりです。

Sub Search(directory) 
    Dim flag 
    Dim found 
    Dim nodeinfo(4) 
    Dim ipath 
    On Error Resume Next 
    Set fldr = fso.GetFolder(FolderPath) 
    Set Fls = fldr.Files 
    For Each item In Fls 
     sFSpec = FSO.GetAbsolutePathName(item) 
     If LCase(FSO.GetExtensionName(item.Name)) = "xml" Then 
      objMSXML.async = True 
      '... 
      'More code here to generate table mytable ... 
      '... 
     End If 
    Next 
    Set fldrs = fldr.SubFolders 
    For Each item In fldrs 
     Search item.path 
    Next 
End Sub 

テーブルにデータがある場合には現在、私は、検索ボタンを無効にしています:

If no_of_occurence > 0 Then document.getElementById("search_btn").disabled = True 

編集

生成するにはテーブル:

Set mytable = document.createElement("table") 
mytable.setAttribute "id", "mytable" 
mytable.setAttribute "align", "center" 
Set thead = document.createElement("thead") 
Set tr = document.createElement("tr") 
Set th = document.createElement("th") 

th.setAttribute "colSpan","5" 
thead.appendChild tr 
Set tr2 = document.createElement("tr") 
Set th1 = document.createElement("th") 
Set th2 = document.createElement("th") 
Set th3 = document.createElement("th") 
Set th4 = document.createElement("th") 
Set th5 = document.createElement("th") 
th1.innerText = "ABC" 
th2.innerText = "DEF" 
th3.innerText = "GHI" 
th4.innerText = "JKL" 
th5.innerText = "MNO" 
tr2.appendChild th1 
tr2.appendChild th2 
tr2.appendChild th3 
tr2.appendChild th4 
tr2.appendChild th5 
thead.appendChild tr2 
mytable.appendChild thead 

Set td1 = document.createElement("td") 
td1.innerText = nodeinfo(0) 
tr3.appendChild td1 

結果が返される場合は数値を保持する変数、たとえばno_of_resultsがあります。その変数に基づいて、ボタンを無効にしています。

答えて

1

彼らはまだ存在しない場合にのみ<table>(および<thead>)を作成します。

Set mytable = document.getElementById("mytable") 
If mytable Is Nothing Then 
    Set mytable = document.createElement("table") 
    '... 
    Set thead = document.createElement("thead") 
    '... 
    mytable.appendChild thead 
End If 

をそして、あなたは新しいものを追加する前に既存の検索結果を削除することができますので、<tbody>にテーブルの内容を置く:

For Each tbody In mytable.getElementsByTagName("tbody") 
    mytable.removeChild(tbody) 
Next 

Set tbody = document.createElement("tbody") 
'... 
'create rows and cells and append them to the table body 
'... 

mytable.appendChild tbody 
1

私もこのような問題がありましたが、私の場合はJavascriptを使い、この状況を別の方法で処理しました。この場合、クリア関数とロード関数の両方を呼び出す別の関数を試してください。

チェックします........

<input name="Search" type="button" class = "buttongo aright" value="Search" OnClick="window.location.reload(); Search();"> 
+0

はクールなサウンドをクリックし、単一のボタンの2つの機能を呼び出して、このコードを試してみてください。 :-) – user2816085

+0

両方の機能を呼び出す際に問題が発生しました... – user2816085

関連する問題