IE. Document.items.all does not work hta - forms

I am making a tool for work that generates a new project item on our sharepoint.
On the sharepoint we have a form that needs to be filled in and to identify the textfields of the form I use the IE.Document.All.Item("id").value=value command.
It works in a separate vbs file, but when I try to launch it from hta it blocks at the IE.Documents.All.item command. Does anybody knows how to solve this?
The code looks like the following (language: vbscript):
Sub SendProjectData
Set IE = CreateObject("InternetExplorer.Application")
set WshShell = CreateObject("WScript.Shell")
IE.Navigate "https://sharepointpage"
IE.Visible = true
sleep1 6000 'external defined sleep command'
IE.Document.All.Item("projectid").Value = "projectname"
WshShell.AppActivate "IE"
WshShell.SendKeys "{ENTER}"
End Sub

Mmmh, I work with:
oIe.document.getElementById("testMsgBox").value = "hallo"
or
oIE.document.all.testMsgBox.value = "hallo"
Perhaps that helps, Reinhard

This should work. Tested under Win10 with IE11:
First the HTML test file:
<html>
<head><title>MyInputFile</title></head>
<body>
<h1>IE with Input field</h1>
<input type="text" id="myText" value="Default text" size="20">
</body>
</html>
Now the HTA file to fill out the html File:
<html>
<head>
<title>Hypertext-Application Demo</title>
<HTA:APPLICATION ID="oHTA">
<script language="vbscript">
sub Window_Onload
self.resizeto 500,200
self.MoveTo 50,50
End Sub
Sub fillHta()
myText.value = "New Text"
End Sub
Sub startAndFill()
set wsh = CreateObject("WScript.Shell")
'Set oIE = CreateObject("InternetExplorer.Application")
Set oIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
oIE.Navigate "d:\MyInputFile.html"
oIE.Visible = true
Do: Loop Until oIE.Busy = False
Do: Loop Until oIE.Document.ReadyState = "complete"
oIe.document.getElementById("myText").value = "New Text" 'use this
x = oIe.document.getElementById("myText").value
oIE.document.all.myText.value = x & "; New Text2" 'or this
End Sub
</script>
</head>
<body bgcolor="#99CCFF">
<p>Simple Demo of Hypertext Applikationen</p>
<input type="button" value="Fill HTA input field" onclick="fillHta()">
<input type="text" id="myText" value="Default text" size="20">
<p><input type="button" value="start and fill IE field" onclick="startAndFill()"> D:\MyInputFile.html</p>
</body>
</html>
Enjoy, Reinhard

Related

perl, mason, working and passing variables

I'm trying to pass a 'mason' variable into a Perl autohandler script that runs before the HTML.
Is this possible.
<!--- MASON -->
<html>
<body>
<%init>
my $sub_headline = 'this is text';
</%init>
###HEADER###
</body>
</html>
<!--- AUTOHANDLER --->
my $m_header = '<div class="m-portlet__head">
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<h3 class="m-portlet__head-text">###TITLE###</h3>
</div>
<p>$sub_headline</p>
</div><!-- /.caption -->
</div><!-- /.head -->';
$html =~ s/###HEADER###/${m_header}/i;
Ended up making a component for the header and adding a condition for the passed in arg. Then pirnt the correct HTML.

HTA: Show text file in a scrollable popup window

I'm looking for a minimalistic way to view the contents of my text (.txt) file.
I can call the file with notepad, but I don't want a user to be able to directly edit the file.
Is it possible to show the content in a scrollable popup window? Preferably without the use of javascript.
I created a new sub .hta which I call from my main .hta
Works great except when I convert the sub .hta to a .exe with HTAEdit, it won't open my log file :/ Well that's another issue to solve :)
Here's my sub .hta code:
<head>
<title>Log File Viewer</title>
<HTA:APPLICATION
INNERBORDER="no"
SYSMENU="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SCROLL="no"
SCROLLFLAT="yes"
SHOWINTASKBAR="no"
CONTEXTMENU="no"
SELECTION="no"/>
</head>
<script language="Javascript">
window.resizeTo(600,450); // Width,Height
window.moveTo(window.screen.width/3,window.screen.height/3);
</script>
<script language="VBScript">
Dim strHTML
Sub Window_OnLoad
logfile = "LOG_" & DatePart("yyyy",Date) & "_" & Right("0" & DatePart("m",Date), 2) & ".txt"
strHTML = ""
strHTML = strHTML & "<div id='list'>"
strHTML = strHTML & "<p><iframe src='logs\" & logfile & "' frameborder='0' height='330' width='100%'></iframe></p>"
strHTML = strHTML & "</div>"
LogViewer.InnerHTML = strHTML
End Sub
Sub ClosePopup
window.close
End Sub
</script>
<body>
<div id="LogViewer"></div>
<center><input type="button" id="Close" value="Close Log Viewer" onclick="VBScript:ClosePopup"></center>
</body>
</html>

PHP 5.3 write contents to plain text

I am trying to make a PHP script write into a plain text file. I have done this before and it worked just fine. But it's not working this time for some reason.
Here is the HTML I am using:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="/css/feedback.css" >
<title>Questions, Comments, Suggestions</title>
</head>
<body>
<p class="title">Questions, comments, and suggestions here!</p>
<form method="post" name="userFeedback" action="/submit.php">
<textarea id="comments" placeholder="Leave a comment or review here..."></textarea>
<textarea id="name" placeholder="Your name here"></textarea>
<textarea id="contact" placeholder="Put any means of contact you want to here (optional)"></textarea>
<br>
<input class="enter" type="submit" value="Enter">
</form>
</body>
</html>
All I want to do with this is to print out whatever is entered onto a plain .txt file with PHP 5.3. Here is the code:
$data = ($_POST["comments"] ." || ". $_POST["name"] ." || ". $_POST["contact"]);
$data = strip_tags($data);
$file = "feedback.txt";
$f = fopen($file, "a+");
fwrite($f, $data . "\n" . "\n");
fclose($f);
header ( 'Location: index.html' );
Please remember that I am using 5.3. I'm sure there's a simple error in here somewhere. Can someone help me with this? Thank you in advance!
We got it! Turns out that the PHP $_POST method looks for the "name" attribute and not the "id".

HTA Vbscript FileSystemObject and DOM

Below is prototype code, which I am writing for getting content of text files present in a particular folder into div of .hta document.
using document.write I could easily write on document, but I want to write content of text files to specific div.
When I try to run the code, nothing happens.
<html>
<head>
<title>Notes</title>
<script language="vbscript">
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = "C:\Documents and Settings\anamdev\Desktop\demo.txt"
Set fileObj = fso.GetFile(FileName)
Set ts = fileObj.OpenAsTextStream(1, -2)
Set objDiv = Document.getElementById("content")
objDiv = ts.ReadAll
Do While ts.AtEndOfStream <> True
TextLine = ts.ReadLine
Document.getElementById("content").innerHtml TextLine & "<br />"
Loop
ts.Close
</script>
</head>
<body>
<span id="head"></span>
<input type="button" value="Previous" name="pre" />
<input type="button" value="Next" name="nxt" />
<hr>
<div id="content">
</div>
</body>
</html>
The problem is that the code in your <script> is executed as the page is being parsed. This means that at the time the script is run, the "content" element doesn't exist. I would expect that you're actually getting an "Object required" error that isn't being displayed for whatever reason.
There are at least two ways to address this:
Move the script block to the end of the document, just before the close </body> tag:
<html>
<head>
<title>Notes</title>
</head>
<body>
<span id="head"></span>
<input type="button" value="Previous" name="pre" />
<input type="button" value="Next" name="nxt" />
<hr>
<div id="content">
</div>
<script language="vbscript">
Document.getElementById("content").innerHtml = "Hello!"
</script>
</body>
</html>
Wrap the initialization code in a subroutine and call it from the window object's onload event handler:
<html>
<head>
<title>Notes</title>
<script language="vbscript">
Sub Init
Document.getElementById("content").innerHtml = "Hello!"
End Sub
Set window.onload = GetRef("Init")
'Alternatively, you could do this to the <body> element:
' <body onload="Init()">
</script>
</head>
<body>
<span id="head"></span>
<input type="button" value="Previous" name="pre" />
<input type="button" value="Next" name="nxt" />
<hr>
<div id="content">
</div>
</body>
</html>
The Cheran Shunmugavel answer is correct (+1), I'll only append some other issues that I see in the code.
Set objDiv = Document.getElementById("content")
objDiv = ts.ReadAll
Above not make sense. You set an Object to variable objDiv and immediately overwrite this variable with String on the next line.
Anyway, after ReadAll your TextStream is already reach EOF, so next loop do nothing:
Do While ts.AtEndOfStream <> True
TextLine = ts.ReadLine
Document.getElementById("content").innerHtml TextLine & "<br />"
Loop
Also the assignment is wrong.
Object.Property Value 'incorrect
Object.Property = Value 'correct
Briefly, you can go like this:
Set objDiv = Document.getElementById("content")
objDiv.innerHtml = ts.ReadAll
ts.Close

GET/POST variable not set in netbeans IDE

I dunno if its a silly mistake but a post/get variable is not being set, while it is supposed to be. Here are the HTML and php code snippets:
<html>
<head>
<title>
Chain Story
</title>
</head>
<body>
<form method="GET" action="check-valid.php">
<textarea name="a" rows="5" cols="50"></textarea>
<input type="submit" value="Add" />
</form>
</body>
</html>
check-valid.php:
<?php
require 'includes/connect.inc.php';
$conn_ref = connect_db('chainstory') or die(mysqli_error());
if(isset($_GET)){
echo 'Get variable set';
if(isset ($_GET['a'])){
$as = $_GET['a'];
$query = "insert into story1 values (1, " . $as . ")";
mysql_query($query, $conn_ref);
}
else{
echo $_GET;
}}
?>
I get the following output:
Get variable set
Notice: Array to string conversion in /home/kevin/Code/php/myWebsite/check-valid.php on line 15
Array
I am coding this in netbeans. Can anyone point me out what mistake im making? :(
Did you try rename the textarea? Longer name , and give id to textarea same the name.
What browser does you use for testing?
I met some problems with input names in IE for example if an input name matches a javascript function name or protected names. Have you a javascript function or variable in your code what's name is a ? Because if the name of the input conflicts with a js var or name IE does not send the input field to the server. (Chrome Firefox and other browsers does)