Form validation in an HTA file - validation

How can I perform a simple validation on this HTA form to make sure that data is inputted and an option is selected? This should be simple, I'm not sure what I'm missing.
Any answers or suggestions would be appreciated.
Thanks.
<html><head><title>Write data to text file</title>
<HTA:APPLICATION
border="thin"
borderStyle="normal"
caption="yes"
maximizeButton="no"
minimizeButton="yes"
showInTaskbar="yes"
innerBorder="yes"
navigable="yes"
scroll="auto"
scrollFlat="yes" />
<script language="javascript">
window.resizeTo(480,150)
function Writedata()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var write_id;
write_id = document.getElementById('write_id').value ;
alert('The data has been written to \n' + write_id);
var s = fso.OpenTextFile(write_id, 8, true);
s.WriteLine(document.getElementById('name_id').value);
s.Close();
}
</script>
</head>
<body>
<table>
<tr>
<h3>Input some information</h3>
<form>
<td>Input: </td><td><input type="text" name="name" value="" id="name_id"></td>
<td><select id="write_id">
<option name="write" value="">Select an Option</option>
<option name="write" value="C:\temp\option1.txt">Option1</option>
<option name="write" value="C:\temp\option2.txt">Option2</option>
</select></td>
<td><input type="button" onclick="Writedata()" value="submit"></td>
</form>
</tr>
</table>
</body>
</html>

I was stumped, so I rewrote this in vbscript.
I have included bits of what I did to give you an idea of how to write to a text file, and validate your form with an HTA.
The vbscript:
Set wshShell = CreateObject( "WScript.Shell" )
strSender = wshShell.ExpandEnvironmentStrings( "%USERNAME%" ) ' Get the current Username
Dim Checkmark
Sub Validate
If form.Flag.checked = True Then ' Find out if your Checkbox is checked
Checkmark = "*"
Else
Checkmark = ""
End IF
If form.field1.value = "" Then ' Validate the form
alert "Please enter an number!", "0", "Title"
ElseIf IsNumeric(form.field1.value) = False Then
alert "Please enter a valid number!", "0", "Title"
ElseIf form.drop_down1.Value = "" Then
alert "Please select a save location!", "0", "Title"
ElseIf form.field1.value < 100000 Then
alert "Please enter a six digit number!", "0", "Title"
ElseIf form.field1.value > 999999 Then
alert "Please enter a six digit number!", "0", "Title"
Else
SaveData
End If
End Sub
Sub SaveData ' Write data to a text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(form.drop_down1.Value) Then
Set objFile = objFSO.OpenTextFile(form.drop_down1.Value, 8)
strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender & vbtab & Now ' fields that will be written
objFile.WriteLine strLine
MsgBox "The Information was successfully written to the file.", "0", "Title"
objFile.Close
Else
Set objFile = objFSO.CreateTextFile(form.drop_down1.Value) ' If file does not exist, create file
strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender & vbtab & Now
objFile.WriteLine strLine
MsgBox "The Information was successfully written to the file.", "0", "Title"
objFile.Close
End If
End Sub
The HTML:
<form name="form">
<h2>Imput</h2>
<tr><td><lable>Data: </lable></td><td><input type="text" name="field1" size="25"></td> </tr>
<tr><td><lable>Save Location: </lable></td><td><select name="drop_down1">
<option type="text" name="select" value="">Select an option</option>
<option type="text" value="SavePath1...">SavePath1</option>
<option type="text" value="SavePath2...">SavePath2</option>
<option type="text" value="SavePath3...">SavePath3</option>
</select></td><td><input type="checkbox" name="Flag" value="">Flag *</td></tr>
</table>
<input type="button" value="Submit" onClick="Validate">
<input type='reset' id='ResetFields' value='Clear Fields' />
</form>

Related

Passing Command Line Arguments To HTA Application

I have an HTA application I would like to run from a Command Prompt.
I've tried everything I could possibly think of and it's just not working!
It just launches the application and that's it.
From Command Prompt I run it with the full path as such:
C:\users\xxx\script.hta "arg1" "arg2"
which is essentially what I'm trying to accomplish here?
I've gone through numerous pages on here with similar issues but I guess I'm just not putting it together properly!
Here is the code:
<html>
<head>
<HTA:Application
ID="oHTA"
APPLICATIONNAME="MSI-BUILD"
Border = "NO"
Singleinstance ="YES"
BorderStyle = "Complex"
ShowInTaskBar = "YES"
MaximizeButton = "No"
MinimizeButton = "No"
scroll="NO"
VERSION="2"
/>
<script language = "VBScript">
Sub RunProgram
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
strCurDir= WshShell.CurrentDirectory
StrARG = MSINAME.value
StrARG3 = FPath.value
strFolder = "D:\SMPSS\PROJECTS\"&MSINAME.value
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(strFolder) Then
oFSO.CreateFolder strFolder
End If
objShell.Run "D:\SMPSS\MSI-2\1-newproject.vbs " & StrARG , 0, True
window.close()
End Sub
Sub Window_onLoad
Self.Resizeto 890, 300
document.title = oHTA.applicationName & " v" & oHTA.version
arrCommands = Split(oHTA.commandLine, chr(34))
For i = 3 to (Ubound(arrCommands) - 1) Step 2
Select Case arrCommands(i)
Case "arg1"
myarg1 = "This is argument 1."
Case "arg2"
myarg2 = "This is argument 2."
End Select
Next
MsgBox myarg1
MsgBox myarg2
End Sub
</script>
</head>
<body style="background-color: #b2b2f4">
<td>MSI-NAME:</td>
<td> </td>
<td style="overflow:hidden">
<td style="resize:none">
<td style="text-align:right">
<td style="width: 325px"><input type = "text" name = "MSINAME" id = "MSINAME" size="50" /></td>
<p>
<td>PATH:</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="overflow:hidden"></td>
<td style="resize:none"></td>
<td style="text-align:right"></td>
<td style="width: 325px"><input type = "text" name = "FPath" id = "FPath" value ="" size="50" /></td>
<td> </td>
</p>
<p>
<input id='submit' type="button" value="Submit" onClick="RunProgram"></td>
</p>
</body>
</html>
I figured it out the issue was having <meta http-equiv="x-ua-compatible" content="ie=9"> in my code once removed everything started working as it should thanks! Also the file wasn't saved as ANSI so it was having invalid character errors. Everything is working great now!

Object Doesn't support this method

I am getting a
Object doesn't support this method
when I click the start button. It says the line is;
<input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button">
I believe it actually may be somewhere in my vbscript. When I click on the start button it depending on whether the strPath is entered and the checkbox is checked it should run the program to install, or tell me that I need to enter the strPath or check a box.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tombstone USD #1 - Software Installer</title>
<HTA:APPLICATION
APPLICATIONNAME = "Software Installer"
ICON = "images\districtlogo.ico"
ID = "NAME"
BORDER = "thick"
CAPTION = "yes"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE="normal"
SCROLL = "no"
VERSION = "1.0"
INNERBORDER = "yes"
SELECTION = "yes"
MAXIMIZEBUTTON = "no"
MINIMIZEBUTTON = "no"
NAVIGABLE = "no"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal"
/>
<script type="text/javascript">
<!--Resolution//-->
window.resizeTo(600,750);
</script>
<script language="VBScript">
Sub Start_Button()
Dim strAnswer,strPath, objNetwork
Set objNetwork = CreateObject("WScript.Network")
strAnswer = ""
strPath=""
If chkEset.Checked Then strAnswer = "Eset"
'If strPath is empty then nothing was checked.
If strPath = "" Then
Window.Alert "Please input Path location!"
End If
'If strAnswer is empty then nothing was checked.
If strAnswer = "" Then
Window.Alert "Please Make an Selection!"
Exit Sub
End If
Window.Alert "Done!"
End Sub
</script>
</head>
<body style="background-color:#E6E6FA">
<center>
<img src="images\districtlogo.png" alt="Logo" height="100" width="100"/>
<h1>Software Installer</h1>
</center>
<form name="MainMenu" action="" method="">
<label for="sPath">Drive Letter or File Path:</label><input type="text" size="60" id="sPath" name="sPath"></td>
<br />
<label for="Eset">ESet AntiVirus</label></td><input type="checkbox" id="Eset" name="chkEset">
<br />
<input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button">
<br />
<input type="reset" value="Reset">
</form>
</body>
</html>
I'm currently just trying to get this run with the one program. This is a proof of concept test.
Ok, since I figured it out I thought I would add the completed script below. All this does is check to see if the strPath is filled in and if the checkbox is checked. Next step is to get it to run a program that corresponds to the checkbox.
The way I fixed it was by changing the <input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button"> to <input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button()">.
I also realized that the Form wasn't actually assigning the values to the script and created TheForm value and assigned it to the MainMenu form. I then had to add that value to all the existing values.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tombstone USD #1 - Software Installer</title>
<HTA:APPLICATION
APPLICATIONNAME = "Software Installer"
ICON = "images\districtlogo.ico"
ID = "NAME"
BORDER = "thick"
CAPTION = "yes"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE="normal"
SCROLL = "no"
VERSION = "1.0"
INNERBORDER = "yes"
SELECTION = "yes"
MAXIMIZEBUTTON = "no"
MINIMIZEBUTTON = "no"
NAVIGABLE = "no"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal"
/>
<script type="text/javascript">
<!--Resolution//-->
window.resizeTo(600,750);
</script>
<script language="VBScript">
Sub Start_Button()
Dim strAnswer,strPath, objNetwork,TheForm
Set objNetwork = CreateObject("WScript.Network")
Set TheForm = Document.MainMenu
strAnswer = ""
strPath = ""
If TheForm.chkEset.Checked Then strAnswer = "Eset"
'If strPath is empty then nothing was checked.
If TheForm.strPath = "" Then
Window.Alert "Please input Path location!"
Exit Sub
End If
'If strAnswer is empty then nothing was checked.
If strAnswer = "" Then
Window.Alert "Please Make an Selection!"
Exit Sub
End If
Window.Alert "Done!"
End Sub
</script>
</head>
<body style="background-color:#E6E6FA">
<center>
<img src="images\districtlogo.png" alt="Logo" height="100" width="100"/>
<h1>Software Installer</h1>
</center>
<form name="MainMenu" action="" method="">
<label for="Path">Drive Letter or File Path:</label><input type="text" size="60" id="Path" name="strPath"></td>
<br />
<label for="Eset">ESet AntiVirus</label></td><input type="checkbox" id="Eset" name="chkEset">
<br />
<input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button()">
<br />
<input type="reset" value="Reset">
</form>
</body>
</html>

ASP Visual Basic Code Crashing...Help Much Required

I am trying to insert data into a oracle database
The data gets inserted and updates the database, however the page throws an error each time the insert statement finished even though the database was updated?
How can i fix this bug? Thanks!
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<div class="page">
<h1>Connie's Control Panel</h1>
<div class="header">
<form action="" method="POST">
<table>
<tr>
<td>Supplier You Want To Update:</td>
<td><input type="text" name= "supplierName" required ></td>
</tr>
<tr>
<td>Supplier Name Updated:</td>
<td><input type="text" name= "supplierNameUpdated" required></td>
</tr>
<tr>
<td>Supplier Address Updated:</td>
<td><input type="type" name="supplierAddressUpdated" required></td>
</tr>
<tr>
<td>Supplier Rating Updated:</td>
<td><input type="type" name="supplierRatingUpdated" required></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit">
</form>
<%
Dim objConnection
Dim objRecordset
Dim objUpdateSet
Dim nameCheck
Dim nameUpdate
Dim addressUpdated
Dim ratingUpdated
nameCheck = Request.Form("supplierName")
nameUpdate = Request.Form("supplierNameUpdated")
addressUpdated = Request.Form("supplierAddressUpdated")
ratingUpdated = Request.Form("supplierRatingUpdated")
Set objConnection = Server.CreateObject("ADODB.Connection")
With objConnection
.ConnectionString = "Provider=MSDAORA.1;Password=DELETED;User ID=n011266e;Data Source=stora;Persist Security Info=True"
.Open
Set objRecordset = .Execute("SELECT * FROM Suppliers")
if nameCheck<>"" then
Do while (Not objRecordset.eof)
Set objRecordset = .Execute("UPDATE Suppliers SET SupplierName =" & "'" & nameUpdate &"'" & "WHERE SupplierName =" &"'" & nameCheck&"'")
objRecordset.MoveNext
Loop
end if
End With
objConnection.close
Set objConnection = Nothing
Set objRecordset = Nothing
Set objUpdateSet = Nothing
%>
</div>
<div class="buttons">
<i class="icon-white icon-pencil"></i> Enter Stock
Stock Report
<i class="icon-white icon-pencil"></i> View Suppliers Details
<i class="icon-white icon-pencil"></i> New Supplier
<i class="icon-white icon-pencil"></i> Edit Supplier
</div>
</div>
</body>
</html>
I guess you need not do "SELECT * FROM Suppliers" and Do while loop
you can directly execute
"UPDATE Suppliers SET SupplierName ='nameUpdate' WHERE SupplierName ='nameCheck' "
may be your getting error because your executing on "objRecordset = .Execute(.. ) " which already has select.

HTA : how to pick up value from each drop down list and search?

I am trying to make this HTA working, what it does is to add up all value from each drop down list and search accordingly in a directory that can be selected from another button. I can only make the form of this HTA but dont know how to make the search working.
Also how can I move the directory selection button to the beginning of the line?
so user can pick up directory first then pick what they want to search.
<html>
<head>
<HTA:APPLICATION ID="2014-03"
applicationName="2014-03"
version="1.1"
BORDER="thin"
BORDERSTYLE="static"
CAPTION="Yes"
CONTEXTMENU="no"
ICON="C:\icon\32x32.ico"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGATABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
<SCRIPT LANGUAGE="VBScript">
Sub RunSearch_OnClick()
msgBox "Success!"
End Sub
Sub TestSub
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub TestSub1
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub WindowsLoad
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder (0, "Select The Folder To Enumerate :", (0))
If objFolder Is Nothing Then
Wscript.Quit
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(objPath)
For each objFile in objFolder.Files
If objFolder.Files.Count > 0 Then
Window.Document.Title = "Information For " & objPath
strHtml = strHtml & "<td><Font color = Blue>" & objFile.Name & "</font></Br>"
DataArea.InnerHtml = strHtml
End If
Next
End Sub
</SCRIPT>
</head>
<body>
<select id=extension size="1" name="OptionChooser" onChange="TestSub">
<option value="0">Selet File Type</option>
<option value="1">.txt</option>
<option value="2">.pdf</option>
<option value="3">.jpg</option>
<option value="4">.mp3</option>
</select>
<select id=year size="1" name="OptionChooser" onChange="TestSub1">
<option value="0">Select Year</option>
<option value="1">2014</option>
<option value="2">2013</option>
<option value="3">2012</option>
<option value="3">2011</option>
<option value="3">2010</option>
</select>
<select id=month size="1" name="OptionChooser" onChange="TestSub2">
<option value="0">Select Month</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="1">04</option>
<option value="2">05</option>
<option value="3">06</option>
<option value="1">07</option>
<option value="2">08</option>
<option value="3">09</option>
<option value="1">10</option>
<option value="2">11</option>
<option value="3">12</option>
</select>
<input Type = "Button" Value = "Browse For Folder" Name = "Run_Button" onClick = "WindowsLoad"><p></td>
<input type="button" value="Search" name="RunSearch">
</body>
</html>
The final HTA should look like this, the search result need to be displayed below the drop down list as text file within a scrollable window and having full path of the files.
In next HTA only necessary changes made to display the search result below the drop down list as a scrollable text area and having full paths of the files.
On start, a user is prompted to select initial directory (see WindowsLoad call within the Window_Onload procedure; then all files are displayed as no search criteria selected yet.
Search completed in code for extension only to show a possible how-to approach (one of few).
Used a simple StyleSheet.
Some variables defined script (application) global to keep their visibility within all procedures.
Further elementary changes: see the code below.
The code:
<html>
<head>
<HTA:APPLICATION ID="2014-03"
applicationName="2014-03"
version="1.1"
BORDER="thin"
BORDERSTYLE="static"
CAPTION="Yes"
CONTEXTMENU="no"
ICON="C:\icon\32x32.ico"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGATABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
<!--
'************************
'* StyleSheet
'************************
-->
<style>
BODY
{
background-color: buttonface;
font-family: Arial, Helvetica, sans-serif;
font-size: 8pt;
margin-top: 2px;
margin-left: 8px;
margin-right: 3px;
margin-bottom: 3px;
}
.button
{
font-family: Arial, Helvetica, sans-serif;
font-size: 8pt;
width: 40px;
}
textarea
{
background-color: yellow;
font-family: Arial;
font-size: 8pt;
margin-left: 3px;
margin-right: 3px;
}
</style>
<SCRIPT LANGUAGE="VBScript">
'************************
'* Global Variables
'************************
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
objPath = ""
strHtml = ""
Chooser0 = ""
Chooser1 = ""
Chooser2 = ""
'************************
'* Window_Onload
'************************
Sub Window_Onload
self.Focus()
self.ResizeTo 800,600
DataArea.InnerHTML = "<textarea cols=122 rows=25></textarea>"
WindowsLoad
End Sub
Sub RunSearch_OnClick()
'msgBox "Success!"
WindowsLoad
End Sub
Sub TestSub
If OptionChooser.Value = "0" Then
Chooser0 = ""
Else
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Chooser0 = objOption.InnerText
Exit For
End If
Next
End If
End Sub
Sub TestSub1
For Each objOption in OptionChooser1.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub TestSub2
For Each objOption in OptionChooser2.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub whichFolder
prevPath = objPath
Set objFolder = objShell.BrowseForFolder _
(0, "Select The Folder To Enumerate :", (0))
If objFolder Is Nothing Then
msgBox "Bye!"
self.Close()
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
If prevPath <> "" then WindowsLoad
End Sub
Sub WindowsLoad
If objPath = "" Then
whichFolder
End If
Set objFolder = objFso.GetFolder(objPath)
Window.Document.Title = "Information For " & objPath & " " & Chooser0
strHtml = "<textarea cols=122 rows=25>"
ShowSubFolders objFolder, Chooser0
DataArea.InnerHtml = strHtml
End Sub
Sub ShowSubFolders(fFolder, strExt)
'strHtml = strHtml & Chr(10) & fFolder.Path & Chr(10)
Set objFolder = objFSO.GetFolder(fFolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If strExt = "" OR UCase(strExt) = _
"." & UCase(objFSO.GetExtensionName(objFile.name)) Then
strHtml = strHtml & objFile.Path & Chr(10)
End If
Next
For Each Subfolder in fFolder.SubFolders
ShowSubFolders Subfolder, strExt
Next
End Sub
</SCRIPT>
</head>
<body>
<select id=extension size="1" name="OptionChooser" onChange="TestSub">
<option value="0">Selet File Type</option>
<option value="1">.txt</option>
<option value="2">.pdf</option>
<option value="3">.jpg</option>
<option value="4">.mp3</option>
</select>
<select id=year size="1" name="OptionChooser1" onChange="TestSub1">
<option value="0">Select Year</option>
<option value="1">2014</option>
<option value="2">2013</option>
<option value="3">2012</option>
<option value="3">2011</option>
<option value="3">2010</option>
</select>
<select id=month size="1" name="OptionChooser2" onChange="TestSub2">
<option value="0">Select Month</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="1">04</option>
<option value="2">05</option>
<option value="3">06</option>
<option value="1">07</option>
<option value="2">08</option>
<option value="3">09</option>
<option value="1">10</option>
<option value="2">11</option>
<option value="3">12</option>
</select>
<input Type = "button" Value = "Browse For Folder"
Name = "Run_Button" onClick = "whichFolder"><p>
<input type="button" value="Search" name="RunSearch"><p>
<div id="DataArea" name="DataArea"></div>
</body>
</html>

problem in retrieving records based on multiple form values from database in ASP?

I am not able to retrieve records from Oracle based on multiple inputs.
Here is my code:
Search.asp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SearchMDFnode</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#99CCFF">
<p align="center"><font color="#9966CC" size="5" face="Georgia, Times New Roman, Times, serif"><strong>Records</strong></font></p>
<style>
A:link {text-decoration: none;color: blue;}
A:visited {text-decoration: none;}
A:hover {text-decoration:underline; color: red;}
</style>
<script>
function updateDate(fname){
var instDate = showModalDialog('upd_date.html','Select Date','dialogHeight:375px;dialogWidth:287px;status:no;resizable:no;help:no;');
if (instDate == -1 || instDate == null){
alert("You did not select any date.")
fname.focus()
} else {
fname.value = instDate
}
}
function findNull(frm,tname,optnull,optorder){
var nfname = optnull.value
var ofname = optorder.value
frm.action = "MDFnodeDisplayTable.asp?opt=" + tname + "&nfield=" + nfname + "&order=" + ofname
frm.submit()
}
</script>
<form name="SearchMDFnode" action="Display.asp?opt=MDFnode" method="post">
<table width="68%" border="1" align="center" cellpadding="3" cellspacing="2">
<table width="94%" border="1" align="center" cellpadding="3" cellspacing="2">
<tr>
<td width="19%">CCP_CODE</td>
<td width="22%"><strong>
<select name="CCP_CODE" id="select4" title="BLOCK_HOUSE">
<option></option>
<option>AM</option>
<option>AR</option>
<option>BD</option>
<option>BP</option>
<option>CG</option>
<option>CT</option>
<option>CY</option>
<option>ES</option>
<option>GL</option>
<option>HG</option>
<option>JE</option>
<option>JR</option>
<option>JW</option>
<option>KT</option>
<option>NT</option>
<option>OC</option>
<option>PL</option>
<option>QT</option>
<option>TB</option>
<option>TP</option>
<option>TS</option>
</select>
</strong></td>
<td width="19%">NODE_SITE_ID</td>
<td width="40%"><strong>
<input name="NODE_SITE_ID" type="text" id="NODE_SITE_ID" size="10" maxlength="10" title="NODE_SITE_ID(max 7 digits)">
</strong></td>
</tr>
<tr>
<td>STREET_NAME</td>
<td><strong>
<input name="STREET_NAME" type="text" id="STREET_NAME" size="30" maxlength="30" title="STREET_NAME(max 30 digits)">
</strong></td>
<td>BUILDING_NAME</td>
<td><strong>
<input name="BUILDING_NAME" type="text" id="BUILDING_NAME" size="25" maxlength="25" title="BUILDING_NAME(max 7 digits)">
</strong></td>
</tr>
<tr>
<td height="38">BLOCK_HOUSE</td>
<td><strong>
<select name="BLOCK_HOUSE" id="select3" title="BLOCK_HOUSE">
<option></option>
<option>BLOCK</option>
<option>HOUSE</option>
</select>
</strong></td>
<td>BLOCK_DESC_NO</td>
<td><strong>
<input name="BLOCK_DESC_NO" type="text" id="BLOCK_DESC_NO" size="6" maxlength="6" title="BLOCK_DESC_NO(max 6 digits)">
</strong></td>
</tr>
<tr>
<td>REMARK</td>
<td><strong>
<input name="REMARK" type="text" id="REMARK" size="50" maxlength="50" title="REMARK(max 50 char)">
</strong></td>
<td>EQ_RM</td>
<td><strong>
<input name="EQ_RM" type="text" id="EQ_RM" size="3" maxlength="3" title="EQ_RM(max 6 digits)">
</strong></td>
</tr>
<tr>
<td>TYPE</td>
<td><strong>
<select name="EQ_TY" id="select" title="EQ_TY">
<option>CE</option>
<option></option>
</select>
</strong></td>
<td>CE_TY</td>
<td><strong>
<input name="CE_TY" type="text" id="CE_TY" size="10" maxlength="10" title="CE_TY(max 6 digits)">
</strong></td>
</tr>
<tr>
<td height="32">STATUS</td>
<td><strong>
<select name="STATUS" id="select2" title="EQ_TY">
<option></option>
<option>-</option>
<option>Site Survey</option>
<option>Survey Done</option>
<option>Document Sent</option>
<option>Equipment Installed</option>
<option>Commissioned</option>
<option>Cancelled</option>
</select>
</strong></td>
<td>NO</td>
<td><strong>
<input name="NO" type="text" id="NO" size="3" maxlength="3" title="NO (max 7 digits)">
<input name="UNIT_DESC_NO" type="text" id="UNIT_DESC_NO" size="2" maxlength="2" title="UNIT_DESC_NO (max 1 digits)">
<input name="NO_ME_CCTS" type="text" id="NO_ME_CCTS" size="2" maxlength="2" title="NO_ME_CCTS (max 2 digits)">
<input name="Rack" type="text" id="Rack" size="2" maxlength="2" title="Rack (max 1 digits)">
<input name="INSTALL_BY" type="text" id="INSTALL_BY" size="2" maxlength="2" title="INSTALL_BY (max 2 digits)">
</strong></td>
</tr>
<td height="32"><font color="#000000" size="3" face="Georgia, Times New Roman, Times, serif">Order By</font></td>
<td colspan="5"><select name="oMDFnode">
<option value="STATUS">STATUS</option>
<option value="NO">NO</option>
<option value="CCP_CODE">CCP_CODE</option>
<option value="CCP_CODE">NODE_SITE_ID</option>
</select>
<select name="orMDFnode" id="orMDFnode">
<option value="NO">NO</option>
<option value="STATUS">STATUS</option>
<option value="CCP_CODE">CCP_CODE</option>
<option value="CCP_CODE">NODE_SITE_ID</option>
</select>
<select name="ordMDFnode" id="ordMDFnode">
<option value="CCP_CODE">NODE_SITE_ID</option>
<option value="CCP_CODE">NO</option>
<option value="CCP_CODE">STATUS</option>
<option value="CCP_CODE">CCP_CODE</option>
</select></td>
</tr>
</table>
<p align="center">
<input type="submit" name="Submit" value="Search">
<input type="reset" name="reset" value="Clear">
</p>
</form>
<form name="commNull" method="post">
<tr>
<td height="56" colspan="4"><div align="center">
</div></td>
</tr>
</form>
</body>
</html>
Display.asp
<% option explicit %>
<!-- METADATA TYPE = "typelib" File = "c:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
dim strTitle
dim strF, fname, ropt, j, i, sno, ropt1
dim objRS, strQuery, strConn, strSort,strQuery1
dim strHref
dim nodesiteid
'dim eq_ty
'ropt1 = request("opt1")
ropt = request("opt")
'eq_ty = request("EQ_TY")
nodesiteid = request("NODE_SITE_ID")
strQuery1 = request("NODE_SITE_ID")
Set objRS = Server.CreateObject("ADODB.Recordset")
strConn = "Provider=MSDAORA.1;Password=hr;User ID=hr;Data Source=xe;Persist Security Info=True"
strSort = ""
strF = "CCP_CODE, NODE_SITE_ID, STREET_NAME, BLOCK_HOUSE, BLOCK_DESC_NO, UNIT_DESC_NO, BUILDING_NAME, EQ_RM, EQ_TY, CE_TY , Rack, INSTALL_BY, STATUS, NO, RFS_DATE, REMARK, NO_ME_CCTS, NO_ME_CCTS" 'these were fields in sql table as well as input name in form
fname= split(strF,",",-1,vbtextcompare) 'split the above string to individual field
if trim(strQuery1) ="" then
strQuery = "select rowid,CCP_CODE, NODE_SITE_ID, STREET_NAME, BLOCK_HOUSE, BLOCK_DESC_NO, UNIT_DESC_NO, BUILDING_NAME, EQ_RM, EQ_TY, CE_TY , Rack, INSTALL_BY, STATUS, NO, RFS_DATE, REMARK, NO_ME_CCTS from MDF_NODE where CCP_CODE = CCP_CODE"
else
strQuery = "select rowid,CCP_CODE, NODE_SITE_ID, STREET_NAME, BLOCK_HOUSE, BLOCK_DESC_NO, UNIT_DESC_NO, BUILDING_NAME, EQ_RM, EQ_TY, CE_TY , Rack, INSTALL_BY, STATUS, NO, RFS_DATE, REMARK, NO_ME_CCTS from MDF_NODE where CCP_CODE = CCP_CODE and NODE_SITE_ID="
strQuery = strQuery & "'" & strQuery1 & "'"
end if
strSort = " order by " & request("oMDFnode") & "," & request("orMDFnode") & "," & request("ordMDFnode")
strTitle = "Summary of Carrier Ethernet Node"
if trim(request("nfield"))= "" then
j=0
for i= 0 to ubound(fname)
if request(fname(i)) <> "" then 'process if user input value in field
if j=0 then
strQuery = strQuery & " and " & fname(i) & " like '" & request(fname(i)) & "' " '1st field shd start with where clause
j = j + 1
else
strQuery = strQuery & " and " & fname(i) & " like '" & request(fname(i)) & "' " 'rest shd start with and clause
j = j + 1
end if
end if
next
strQuery = strQuery & strSort
else
strQuery = strQuery & " where " & trim(request("nfield")) & " is null order by " & trim(request("order"))
end if
objRS.Open strQuery, strConn,adOpenStatic,adLockOptimistic,adCmdText 'open recordset query oracle database
if objRS.eof then
objRS.close
set objRS = nothing
response.write "<script>alert('No Rows Selected')</script>" 'if eof mean NO data return
response.write "<script>history.back()</script>"
else
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SdhTermDisplayTable2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#99CCFF"><div align="center">
<p align="left"><strong>
<p> </p>
<p>
</p>
</strong>
<table width=945 align="center">
<tr class="nonPrint" height=30>
<td width="646" nowrap style="vertical-align:middle;font:bolder 12pt verdana;" >
<strong> <font size="4" face="Georgia, Times New Roman, Times, serif"> </font><font size="4" face="Georgia, Times New Roman, Times, serif">
Records/font></strong></td>
</table>
<strong>
<%
if trim(request("nfield"))= "" then
j=0
for i= 0 to ubound(fname)
if request(fname(i)) <> "" then 'process if user input value in field
if j=0 then
strQuery = strQuery & " where " & fname(i) & " like '" & request(fname(i)) & "' " '1st field shd start with where clause
j = j + 1
else
strQuery = strQuery & " and " & fname(i) & " like '" & request(fname(i)) & "' " 'rest shd start with and clause
j = j + 1
end if
end if
next
strQuery = strQuery & strSort
else
strQuery = strQuery & " where " & trim(request("nfield")) & " is null order by " & trim(request("order"))
end if
if objRS.eof then
objRS.close
set objRS = nothing
response.write "<script>alert('No Rows Selected')</script>" 'if eof mean NO data return
response.write "<script>history.back()</script>"
else
call drawHeader(ropt)
objRS.movefirst
sno = sno + 1
do until objRS.eof
call drawB(fname)
sno = sno + 1
objRS.movenext
loop
objRS.close
set objRS = nothing
end if
sub drawHeader(ropt)
response.write "<table id='tbl' table border=1 bordercolor='black' bgcolor='LavenderBlush' cellpadding=1 cellspacing=0 align=center style='BORDER-COLLAPSE: collapse;'>"
select case ropt
case "MDFnode"
response.write "<tr height=20><td><b>SNo</b></td>"
response.write "<td style='font:bold 11pt;' width=50>Exch</b></td><td><b>Cabinet</b></td><td><b>Street Name</b></td><td><b>BLK/HSE</b></td><td><b>No</b></td><td><b>Unit</b></td><td><b>Building Name</b></td><td><b>Room</b></td><td><b>Type</b></td><td><b>Equipment Type</b></td><td><b>Rack</b></td><td><b>Inst By</b></td><td><b>Status</b></td><td><b>ID</b></td><td><b>RFS Date</b></td><td><b>Remark</b></td><td><b>No of ccts</b></td>"
end select
response.write"</tr>"
end sub
response.write"</table>"
sub drawbody(ropt)
response.write "<tr>"
select case ropt
case "MDFnode"
for i= 0 to 10
response.write "<td>" & i & "</td>"
next
end select
response.write"</tr>"
end sub
sub drawB(ofname)
response.write "<tr>"
for i = 0 to ubound(ofname)
if isnull(objRS(i)) then
response.write "<td> </td>"
else
if i = 0 then
strHref = "<a href='e_" & ropt & ".asp?tname=" & ropt & "&rowid=" & server.URLEncode(trim(objRS("rowid"))) & "'>" & sno & "</a>"
response.write "<td style='font:normal 12pt Arial;'>" & strHref & "</td>"
else
response.write "<td style='font:normal 12pt Arial;'>" & trim(objRS(i)) & "</td>"
end if
end if
next
response.write "</tr>"
end sub
end if
response.write"</table>"
%>
</strong></p> </div>
<div align="center">
<input type="button" value="Save as Excel" onClick="vbscript:xlsReport()">
</div>
</p>
</body>
</html>
<script language="VBScript">
dim r, c, colcnt,row
sub xlsReport()
window.status = "Export to Excel ... Please Wait ..."
dim rownow
colcnt = tbl.cells.length / tbl.rows.length
set xls = createobject("Excel.Application")
xls.visible = true
xls.workbooks.add
xls.worksheets.add
for c = 0 to colcnt - 1
xls.cells(3,c+1).value = tbl.rows(0).cells(c).innerText
next
row = 3
for r = 1 to tbl.rows.length -1
for c = 0 to colcnt - 1
xls.cells(row+r,c+1).value = tbl.rows(r).cells(c).innerText
next
next
xls.cells(1,1).value = txtRpt.innerText
set xls = nothing
window.status = "Done"
end sub
</script>
</div>
I am getting records based on CCP_Code and NODE_SITE_ID values.
Now I want to retrieve values only based on TYPE = 'CE' but I am not able to do this.
When I didn't select anything by default the TYPE value is 'CE'. Click submit and it gives me only type CE values.
When I give CCp_code with TYPE = empty then it should give me all the records based on CCP_Code.
When I select CCP_CODE and NODE_SITE_ID it should give me values based on both.
When I select CCP_CODE, NODE_SITE_ID and TYPE='CE' then it should give me values based on these values.
You need to Google "SQL injection" for a start.
strQuery = strQuery & "'" & strQuery1 & "'"
But as a start I'd log the contents of "strQuery" just before the objRS.Open
Once you can see the query text, it should be easy to say why rows were or were not returned.

Resources