Trying to get the full url of input file - javascript

All I get is the images name not the file tree like
C:/document/picture/dangit.gif
Okay, I need to add more text for some reason because stack overflow thinks that I should type more then I need to type so just ignore this text this is so retarded.
<html>
<head>
<script>
function getData() {
var text = document.getElementById("textarea").value;
var text = text.replace(/\r?\n/g, "<br />");
document.getElementById("display").innerHTML = text;
}
function picture() {
var picture = document.getElementById("picture").value;
document.getElementById("pDisplay").src = picture;
document.getElementById("purl").innerHTML = picture;
}
</script>
<title>Gettings a textbox formatting</title>
</head>
<body>
<textarea id="textarea" onkeypress="getData()" autofocus></textarea>
<p id="display">You havnt typed anything yet</p>
<input type="file" id="picture" />
<button onclick="picture()">get the picture from the box</button>
<p id="purl">picture url</p>
<img id="pDisplay" />
</body>
</html>

That's impossible because javascript can't access local storage like hard disk.
The only option is to upload image to the server and then reference it with URL.
If you are using PHP you could start with the documentation http://www.php.net/manual/en/features.file-upload.php
And you need to enclose your <input type="file"> with <form> and provide <input type="submit"> to send the file to the server.

This is not possible due to security restrictions. JavaScript in browser has no access to the File System.

It doesn't work on any of the main browsers (except IE) for security related restrictions

Related

How to create comment section or saveable textarea in R Markdown html document on shared fileserver

I try to create comment section or a saveable textarea with r markdown and a html output.
The comment section should be very simple. Submit Button and an Input Text Field.
The comments should appear above the Input Fields.
Alternatively the input into textarea could be shown in the textarea after loading the html document by another user.
The case is as followed:
I have many users that use one html document on a file server. Each of the users want to make notes in the html document and any user want to see all notes from the other users. So it has to be possible to save notes and when another user open the file the saved notes should be be filled in the html document. There can´t be a big database with the need to install any software on the file server or the users. I have an one file solution in mind like SQLite. So in the result i dont want to share more than two files on the file server.
Is there a simple way to realize this? Is it even possible? Can I use javascript to save and show the input.
I am thankful for any kind of help with storing the input in the database and writing it in the html document. Unfortunately i´m a beginner in html, sql and javascript.
<div id="display"></div>
<div class="comment">
<textarea id="title" type="text "rows="2" cols="100" onkeyup="Allow()" placeholder="write a comment......"></textarea>
<input type="submit" value="Post" onclick="insert()" style="width:100px;" /></form>
</div>
<script type="text/javascript">
var titles = [];
var titleInput = document.getElementById("title");
var messageBox = document.getElementById("display");
function insert () {
titles.push(titleInput.value);
clearAndShow();
}
function clearAndShow ()
{
titleInput.value = "";
messageBox.innerHTML = "";
messageBox.innerHTML += " " + titles.join("<br/> ") + "<br/>";
}
</script>

JavaScript Password check and Open .html file if correct

I need to open a .html file upon password being entered correctly, the file is in the same folder. I have gotten most of it to work but it now says that my password function is not a function. Any help would be much appreciated
my code-
<html>
<head>
<title>Login</title>
</head>
<body onLoad="SetTime()">
<form name="form1">
<label for="password">Enter Password</label>
<input type="password" name="Password" id="password">
<input type="button" onClick="Password()" value="Submit" id="btn">
</form>
<script>
var password = "JavaScript";
var userInput = document.getElementById("password").value;
function SetTime()
{
setTimeout("closeWindow()",120000);
}
function closeWindow(){
window.close();
}
function Password() {
if (userInput == "JavaScript") {
window.open("file:///outcome 3.html")
}
}
</script>
</body>
</html>
First. I hope you know this is not secure. Second, your issues is the fact that your element id/name and function names are the same. Change one of them.
Third, you only read the value when the page is loaded. It does not magically get updated, you need to read the value of the textbox inside of the function.
You cannot open html file like this "file:///outcome 3.html". Please check path of login html and path of redirected html --> define relative path to open.

How do I save changes in online html

What I am trying to do in the code below is to change the text in the Div1 tag with the information in the text input. The thing I want to accomplish is that the text is saved when I reload/quit the page or immediately when it is changed. Is this possible?
Thanks in advance.
<div id="Div1">
<p>Hi</p>
</div>
<input type="text" id='Input'/>
<input type="button" value="submit" onclick="GetInput();" />
<script type="text/javascript">
function GetInput () {
var Input = document.getElementById("Input").value;
document.getElementById('Div1').innerHTML= (Input);
}
</script>
Javascript is a client-side language. This means that the page elements (collectively known as the DOM) are only altered after the page is loaded from the web server and rendered in your browser. Javascript can change these but can not save any data.
In order to save data (persistence), you will need some type of data store. This is usually accomplished with a database running on a server. You will need to get your hands on one or possibly rent some storage space.
Try this, it may help you.
Save value:
localStorage.setItem("name", $('#Input').val());
Get value:
localStorage.getItem("name");

Replacing the new line characters that have been pasted into field - Classic ASP

I am having a problem with some code. I have looked across the web and at stackoverflow and i cannot see what else i can do to resolve the problem for classic asp.
The issue is that i am trying to remove the case return and line feed from being entered into the XML string however i have encounter a flaw in my code but unsure how to stop this from happening.
function DisableEnter()
{
if (window.event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;
}
}
This stops the user from entering the "return" key which is great BUT what happens when you copy and paste the text that has enters in them? In my case it bypasses this check and inputs this into the database.
Server.URLEncode(Replace(Replace(Replace(other_info,","," "),"\n",""),"\r",""))
I have entered this replace to try to resolve the \n\r that i noticed in a lot of posts is the symbols for the carriage return and line feed but it still submits?
<td><textarea name="other_info" cols="30" rows="5" id="other_info" onkeypress="DisableEnter()" onkeyup="DisableEnter()"><%=Request("other_info")%></textarea></td>
Therefore basically the question is how do i eliminate new line/carriage return/line feed from being entered into my database that has been copy and pasted therefore when our process of exporting the data to a CSV spreadsheet for another application to read it which must be on 1 line in the cell.
If you require any other information please let me know.
Thanks for your time.
HI here is an example with javascript.
the code is ready to be copy pasted and tested
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<style>
</style>
</head>
<body>
<div id="container">
<textarea id="data" cols="30" rows="5"></textarea>
<button id="submit">submit</button>
<textarea id="output" cols="30" rows="5"></textarea>
</div>
</body>
<script>
$(document).ready( function (){
$('#submit').click(function(event){
var txt = $('#data').val();
var newstr = txt.replace(/\s/g, '');
$('#output').val(newstr);
});
});
</script>
</html>

Showing only XML files in HTML file input element

How can I show only XML files in a file input element?
I read about the "accept" attribute but also learned no browser actually support it. I found here some JS scripts but they didn't work well :-\
(I'm checking this server side as well but would like to do it client side too)
Thanks
The answer is pretty simple, you use the MIME type. So if it is an xml file you want, you just do:
<input type="file" accept="text/xml" />
If you want to see the full list of MIME types, check this site http://www.iana.org/assignments/media-types/media-types.xhtml
Not sure if you can do that, but at least you could use a callback function and check the input value for the .xml extension.
Snippet:
<script type="text/javascript">
function isXml(input)
{
var value = input.value;
var res = value.substr(value.lastIndexOf('.')) == '.xml';
if (!res) {
input.value = "";
}
return res;
}
</script>
<form method="post" action="">
<input type="file" name="myfile" id="myfile" onchange="return isXml(this)" />
<input type="submit" />
</form>

Categories

Resources