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
Related
In the following code, I wanted the button "Add Lines" to:
run the function 'MoreRentals_fromSidebar' from code.gs in the SpreadsheetApp
then "google.script.host.close();" to close the sidebar
When I try to stack the commands, nothing happens. If I try to invoke the submitForm function to run the two commands, nothing happens (although I thought this was working last week and has now stopped).
Any suggestions would be appreciated.
<!DOCTYPE html>
<script>
function getDataFromHtml(idData) {
if (!idData)
idData = "mydata_htmlservice";
var dataEncoded = document.getElementById(idData).innerHTML;
var data = JSON.parse(atob(dataEncoded));
return data;
}
function initialize() {
var data = getDataFromHtml();
// I would have expected to be able to accept the two parameters but whichever is coded second does not get set.
//document.getElementById("myAgency").innerText = data.agency;
//document.getElementById("myRow").innerText = data.row;
// My workaround is to create the header of the sidebar to contain the agency and the line number
var arr = data.first.split("##");
document.getElementById('myTitle').innerText = arr[0]+"\n# line "+arr[1];
//alert(arr[0]+"\n\n"+arr[1]); // used for debugging
}
window.onload = initialize; //Note that there is no "()". It must be this way for this to work!
</script>
<html>
<head>
<base target="_top">
<script>
function submitForm() {
//alert('in submitForm: '+document.getElementById("RentalLinesForm");
google.script.run.MoreRentals_fromSidebar(document.getElementById('RentalLinesForm'));
google.script.host.close();
}
</script>
</head>
<body>
<h1 id="myTitle" ></h1>
<form id="RentalLinesForm">
<label for="numLines">Number of lines to add</label>
<input type="text" id="numLines" name="numLines"><br><br>
<div>
<label for="location">Where to place the new lines:</label><br>
<input type="radio" id="above" name="location" value="above">
<label for="above">Above line</label><br>
<input type="radio" id="below" name="location" value="below">
<label for="below">Below line</label><br>
<input type="radio" id="bottom" name="location" value="bottom">
<label for="bottom">At bottom</label>
<br><br><input type="button" value="Add Lines" onclick="google.script.run.MoreRentals_fromSidebar(document.getElementById('RentalLinesForm'));">
<br><br><input type="button" value="DONE" onclick="google.script.host.close();">
</form>
</body>
</html>
I am trying to write a simple Regex Checker function that takes the user input and checks it against certain criteria. Only problem is, I can't get the user input to be passed into the new variable to begin the checking.
Can someone help me understand why I'm not seeing the user input in the log? I just want to be able to see the user input in the console so I can continue writing the code I need. EDIT-I know it is set to ALERT at the moment and not console.log-
let first = document.getElementById('firstName').value;
let last = document.getElementById('lastName').value;
function regexChecker () {
alert(first + last);
};
<!DOCTYPE html>
<html>
<head>
<title>Regex Checker</title>
</head>
<body>
<form id='form'>
<h2>Please enter your first and last name</h2>
<label for='firstName'>First Name: </label>
<input type='text' id='firstName'>
<label for='lastName'>Last Name: </label>
<input type='text' id='lastName' >
<button onclick='regexChecker()' type='reset'>Verify Input</button>
</form>
<script src='./script.js'></script>
</body>
</html>a
Thanks in advance.
Just assign values of first and last inside the function cause these two lines invoke when the page loads so have null or empty string values. You must reassign them.
function regexChecker () {
let first = document.getElementById('firstName').value;
let last = document.getElementById('lastName').value;
alert(first + last);
};
<!DOCTYPE html>
<html>
<head>
<title>Regex Checker</title>
</head>
<body>
<form id='form'>
<h2>Please enter your first and last name</h2>
<label for='firstName'>First Name: </label>
<input type='text' id='firstName'>
<label for='lastName'>Last Name: </label>
<input type='text' id='lastName' >
<button onclick='regexChecker()' type='reset'>Verify Input</button>
</form>
<script src='./script.js'></script>
</body>
</html>a
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.
I'm having trouble with learning laravel and decided to ask my question here since I can't find an answer via Google etc.
I am trying to return a client from the database via Id, maybe later via name.
This is my form:
<<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Klant invoeren</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
</head>
<body>
<p><<form action="{{route('client/'.$client->id.'/show/')}}"
method="get">
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
<label for="price">Achternaam:</label>
<input type="text" class="form-control" name="id">
</div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
{{csrf_field()}}
<button type="submit" class="btn btn-success" style="margin-
left:38px">Zoek klant</button>
</div>
</div>
</form></p>
</body>
</html>
Which redirects to:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Klant invoeren</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
</head>
<body>
<div class="container">
<h2>Voer een klant in</h2><br />
<h1>Showing {{ var_dump($client) }}</h1>
</div>
</body>
</html>`
And this is the show method from the Clientcontroller:
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
This is the route I'm using:
Route::get('client/{id}/show','ClientController#show');
Can someone spot my mistake, because I can't after messing with this the last few hours.
EDIT: updated code and added the route, now getting the error that the client variable isn't defined in the
You must echo the client id in the form action. So, remove the inverted comma from $client->id. Use the following code :
<form action="{{action('ClientController#show', $client->id)}}"
method="get">
Additionally, remove backtick from the code. Use the following code :
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
In your routes/web.php
Route::get('client/{id}/show','ClientController#show');
In your form:
<form action="{{URL::to('client/'.$client->id.'/show/')}}"
method="get">
In your controller:
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
In your Client Controller make sure you use the Model that you are referencing to
Assuming App\Client.php Change it to App\User.php if you are referring to user
ClientController
use App\Client;
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
Now you can fetch the client model with $client For example $client->id
Make sure you pass the {id} parameter in the route
I want to only hide the P0 paragraph using childNodes[x] . I wonder how it works because it hides the whole div with in this code:
<html>
<body>
<div id="myDiv">
<p>P0</p>
<p>P1</p>
</div>
<button onclick="hideFn();">hide</button>
<script>
function hideFn()
{
document.childNodes[0].childNodes[1].childNodes[1].style.display = "none";
}
</script>
</body>
</html>
</html>
You easily could have found the reason yourself by simply doing the traversal step by step:
document
the document
.childNodes[0]
the documentElement, also known as the root node (<html>)
.childNodes[1]
the <body>
.childNodes[1]
the <div>