I am trying to use [objshell browseforfolder] with vbs in HTML to make a folder browser. It is working fine in hta but when I put it into html page, it always show me that permission denied. I did some research on this, looks like IE does not support folder browse for security reason.....so my question is that is there anyway to make it work? I m using it on a internal page, so security wont be an issue.....
Here is the code:
<html>
<head>
<script language = "VBScript">
Sub ChooseSaveFolder_OnClick()
strStartDir = "c:\work"
userselections.txtFile.value = PickFolder(strStartDir)
End Sub
Function PickFolder(strStartDir)
Dim SA, F
Set SA = CreateObject("Shell.Application")
Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not F Is Nothing) Then
PickFolder = F.Items.Item.path
End If
Set F = Nothing
Set SA = Nothing
End Function
</script>
</head>
<body>
<form name="userselections">
<input type = "text" name = "txtFile" size="50" />
<input type = "button" value = "Browse ..." Name="ChooseSaveFolder">
</form>
</body>
</html>
Related
I have an html form containing this code which runs on IIS:
<form action="http://server1/data.asp" method="POST">
Your Name: <input name="name" type="text">
<input value="Save" type="submit">
</form>
After user submits this form it runs the code in data.asp which displays a Success message with code to write to a text file (file1.txt):
Success!
<%
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
%>
This works but it just shows a page with Success! and stays there. What I'd really like is:
After user submits the form by clicking Save I'd like a little message box that says "Success" and remain on the same html page or go to a url I specify within the code.
I don't want to use Java or 3rd party extensions. This is an HTML page that runs the data.asp page on submit and I'd like it to stay that way if possible.
So how would I modify the html and/or data.asp page to do this?
You can do like this:
Response.Redirect "https://www.yoursite.com/thankyou.asp"
Instead of returning "Success!" as your response content you can return the form content you have above, this way you can use the same file for the GET and POST methods, with an condition on your asp logic to execute only on POST requests and return a success alert when the code is excuted successfully.
<form action="http://server1/index.asp" method="POST">
Your Name: <input name="name" type="text">
<input value="Save" type="submit">
</form>
<%
If (Request.Method = "POST") Then
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
response.write ("<script>alert('Success!');</script>")
End If
%>
Found the solution by adding an extra page to the mix (redir2form.asp):
in data.asp:
<%
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
%>
Response.Redirect "http://server1/redir2form.asp"
in redir2form.asp:
<%
response.write ("<script>alert('Success!');</script>")
%>
<meta http-equiv="refresh" content="1; url=http://server1/index.htm" />
Index.htm has the form action going to the data.asp page.
Not as neat as it could be but that's how I got it to work. After a user submits the form he gets the "Success!" message box and once they click OK they're redirected back to the form page.
So I have an html form created in classic asp that has about 25 check boxes with different labels. The checkboxes are written to the page via a loop that grabs the label values from a table and each checkbox is named similarly ("decreason1","decreason2","decreason3",ect...) using a loop variable.
I use a vbscript at the end of the page to validate the data on the page before passing with a submit button. I need to make sure that at least one of the checkboxes is checked before submitting the form.
dim i, checkedvalue ;
checkedvalue = false
for i = 1 to 25
if document.rtftadd.decreason1.checked = true then
checkedvalue = true
end if
next
I need the "document.rtftadd.decreason1.checked" to change with the loop to decreason2, decreason3
I'm not sure how to go about doing that.
Any help would be greatly appreciated.
There are a few different ways to do this and if you are seeking a validation method prior to form submission then JavaScript may be a better solution.
However, in an effort to address your question using only ASP Server side code for VBScript and considering your question suggest that you do not care which box is selected nor how many are selected then the following code may be a working solution for you.
By looking at all of the elements sent via the form and checking if your form name (without number) exist then this same block of code will work even if you increase or decrease the number of check boxes you are validating for input.
<%#LANGUAGE="VBSCRIPT"%>
<%
dim checkedvalue
checkedvalue = false
if request("btn1") = "Submit" then
For each item in request.form
if instr(item,"decreason") > 0 then
checkedvalue = true
end if
next
response.write "Checked Value = " & checkedvalue & "<br><br>"
end if
%>
<html>
<head></head>
<body>
<form method="post" action="index.asp" name="rtftadd">
<input type="checkbox" name="decreason1"> Box 1<br>
<input type="checkbox" name="decreason2"> Box 2<br>
<input type="checkbox" name="decreason3"> Box 3<br>
<input type="checkbox" name="decreason4"> Box 4<br>
<input type="checkbox" name="decreason5"> Box 5<br>
<br>
<input type="submit" value="Submit" name="btn1">
</form>
</body>
</html>
I have an HTML page that has multilpe submit buttons with different "value=xxx" parameters. I need to submit the form with the right value via VBA code in MSAccess module!
<form method="post" name="data" action="/data1/infoProjetFO.php" onsubmit="return(checkPQ())" >
<input type="submit" name="Btn" value="SaveRecord">
<input TYPE="submit" name="Btn" VALUE="Distribution" id="idBtnDistribution" style="visibility:visible;" /> 
'========================================================
sURL = "http://corp.myintrranet.com/index.php"
Set tBrowser = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
tBrowser.navigate sURL
' Wait till the Browser is loaded
Do While tBrowser.Busy Or tBrowser.ReadyState <> 4
DoEvents
Debug.Print tBrowser.ReadyState
Loop
' here I have code that can get different values and also insert values with no problem!
'here is what I've tried!
tBrowser.Document.Forms("data").all("Btn").Value = "SaveRecord"
tBrowser.Document.Forms("data").all("Btn").Click
' or I tried
tBrowser.Document.Forms("data").all("Btn").submit
combinations I've tried to insert the proper submit button value result in trapping error code 438, object doesn't support ....
So I need to click or submit with the right value!
Thanks
Pete
Found the solution!
Set Formtst = tBrowser.Document.getElementsByTagName("input")
For Each btest In Formtst
If btest.Value = "SaveRecord" Then
btest.Click
Exit For
End If
Next
Thanks
Pete
This has got to be an easy one, but I'm pulling my hair out.
I'm writing a new HTA, written several before now - but I can't get the InnerHTML property to work.
The error I recieve is on line 10. The error is:
Object doesn't support this property or method: 'text1.innerHTML'
I have compared my text1.innerHTML code areas to that in other HTA's that work fine and cannot see any difference. I've also checked the header / meta info and there's nothing different there.
Below are the snips of code:
<script language="VBScript">
Sub Window_OnLoad()
Self.resizeTo 800,670
Set objShell = CreateObject("WScript.Shell")
strShort = objShell.ExpandEnvironmentStrings("%USERDOMAIN%")
If strShort = "DOMAINA" Then text1.innerHTML="VPN Type 1"
If strShort = "DomainB" Then text1.innerHTML="VPN Type 2"
'This method will be called when the application loads
'Add your code here
End Sub
Sub EnableUpgrade()
If UACheckbox.Checked = True Then
UpgradeButton.Disabled = False
Else
UpgradeButton.Disabled = True
End If
End Sub
Sub OnClickButtonUpgradeButton()
'This method will be called when button "UpgradeButton" is clicked
'Add your code here
End Sub
</script>
<html>
<head>
<title>Test HTA</title></title>
<link href="Main.css" rel="stylesheet" type="text/css" />
<HTA:APPLICATION
APPLICATIONNAME="Babcock GlobalProtect Deployment"
ID="GlobalProtectDeployment"
VERSION="1.0"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SCROLL="auto"/>
</head>
<body bgcolor="white">
<div class="wrappr">
<table class="top">
<tr class="top">
<td colspan="2">
<div class="wrapper">
<div class="topone" align=left><img style="width:125px;border:0;" vertical-align"center" src="WebVersion.png"></div>    
<div class="topthree"><h1>Test HTA</h1>
</td>
</tr>
</table>
<table>
<tr><td>
<br>This upgrade will replace the <span ID = "Text1"> VPN software on this computer. This is mandatory, as <span ID = "text1"> will soon be decomissioned. The new VPN software that will be installed is VPNC.
</td></tr>
<br>
<input onclick="EnableUpgrade "type="checkbox" name="UACheckbox" id="UACheckbox"> I confirm I have completed the above requirements
<br>
<input type="button" name="UpgradeButton" id="UpgradeButton" value="Upgrade" onclick="OnClickButtonUpgradeButton" disabled>
</table>
</div>
<!--Add your controls here-->
<!--{{InsertControlsHere}}-Do not remove this line-->
</body>
</html>
You are not closing the span tag in:
<br>This upgrade will replace the <span ID = "Text1"> VPN software on this computer. This is mandatory, as <span ID = "text1"> will soon be decomissioned. The new VPN software that will be installed is VPNC.
And id of elements should be unique in the page.
I think what you need is:
<br>This upgrade will replace the <span ID = "Text1"></span> VPN software on this computer. This is mandatory, as <span ID = "Text2"></span> will soon be decommissioned. The new VPN software that will be installed is VPNC.
And in the onLoad function,
If strShort = "DOMAINA" Then
Text1.innerHTML="VPN Type 1"
Text2.innerHTML="VPN Type 1"
End if
I have a button in HTA file, it will search certain strings then output the result.(Thanks for #Ansgar Wiechers) I want to output the result in side of this HTA window instead of popping up a message box. The result will fill in the blank "YOU ARE IN _____ MODE"
How can I do it?
<html>
<head>
<title></title>
<HTA:APPLICATION
APPLICATIONNAME=""
ID=""
VERSION="1.0"/>
</head>
<script language="VBScript">
Sub RUNCURRENTMODE
Set xml = CreateObject("Msxml2.DOMDocument.6.0")
xml.async = False
xml.load "C:\aaa\settings.xml"
If xml.ParseError Then
MsgBox xml.ParseError.Reason
self.Close() 'or perhaps "Exit Sub"
End If
For Each n In xml.SelectNodes("//CSVName")
Select Case n.Attributes.GetNamedItem("Value").Text
Case "standard.csv" : MsgBox "This is standard."
Case "non-standard.csv" : MsgBox "This is non-standard."
Case Else : MsgBox "Unexpected value."
End Select
Next
End Sub
</script>
<body bgcolor="buttonface">
<center>
<p><font face="verdana" color="red">YOU ARE CURRENTLY IN STANDARD CSV MODE</font></p>
<input id=runbutton class="button" type="button" value="CURRENT MODE" name="db_button" onClick="RUCURRENTMODE" style="width: 170px"><p>
</center>
</body>
</html>
Normally you'd put an element with an ID into the <body> section of the HTA, for instance a paragraph. Or a span, since you want to update only a portion of the text:
<body>
<p>You are in <span id="FOO"></span> mode</p>
</body>
and change the value of the element with that ID in your function:
Select Case n.Attributes.GetNamedItem("Value").Text
Case "standard.csv" : FOO.innerText = "standard."
Case "non-standard.csv" : FOO.innerText = "non-standard."
Case Else : MsgBox "Unexpected value."
End Select