This question already has an answer here:
How to set file input value when dropping file on page? [duplicate]
(1 answer)
Closed 5 years ago.
Note:
The answers & comments below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017.
See the answer in this question for details as well as a demo:How to set file input value programatically (i.e.: when drag-dropping files)?
Hello everyone is there any way to set input type file's value from my url ? When I add my image file destination to value it can't be displayed
Here is my view:
<div class="editor-label">
<input type="file" name="file" id="file" value="../../banner_image/test.jpg" required="required" />
</div>
Generally - NO WAY! This filed is protected and in some cases you can get the filename (not the whole path) but ... in some browsers. Not possile to set it via html value attribute or using JS.
Related
This question already has answers here:
How to prevent XSS with HTML/PHP?
(9 answers)
Closed 3 years ago.
Probably this is a known problem and there is a specific best practice.
I have to fill a text field value with received text from backend.
I this text contains some 'special characters' (for example " <) I have some issued during the rendering of the page.
How can I solve this?
Can I solve this issue front-end side?
I can use only javascript front-end side. I not use PHP;
I use this html code:
<input class="myclass" value="<%= text_from-backend %>" placeholder="My Placeholder"/>
You can replace special characters in PHP:
<input class="myclass" value="preg_replace('/[^ a-z\d]/ui','','<%= text_from-backend %>');" placeholder="My Placeholder"/>
This question already has answers here:
getAttribute() versus Element object properties?
(7 answers)
Closed 5 years ago.
I have a simple web-application with an input text field in it looking like this:
<input id="txtip" type="text" value="10.1.1.50" />
The address 10.1.1.50 is a default value for an ip address. And from javascript I would read it like this:
txtip.getAttribute("value")
Now let's suppose to change it to 10.1.1.49. In google chrome the above javascript code will still return 10.1.1.50, while the expression
txtip.value
returns 10.1.1.49.
What is the difference? What is the "right way"?
var el = document.getElementById('testBox');
$(document).focusout(function () {
alert('el.value = ' + el.value);
alert('el.getAttribute("value") = ' + el.getAttribute('value'));
e.preventDefault();
});
<h2>Change value in the text box</h2>
<input id="testBox" type="text" value="original value" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Found this on web might help you try following code type something and focusout
The difference is that element.value is real time and if a user changes let's say, a textbox input, it will reflect that, and show you the new value.
While getAttribute('value') will still show the original value="whateverWasHere" value.
This question already has answers here:
jQuery Data vs Attr?
(3 answers)
Closed 6 years ago.
<p id="getMessage" data-sid="158">
<strong>Name</strong> : Rahul Kumar<br>
<strong>Total </strong> : 25<br>
</p>
This is my dynamically generated HTML using jQuery
Now this is stable and fix
I executed several commands in Consol and found these results
$('#getMessage').attr('data-sid');
"158"
This is as expected.
But when I execute this
$('#getMessage').data('sid');
160
It shows 160, it should be 158 right ?
I used $('#getMessage').attr('data-sid', result.studentDetails.SID); to set it.
.attr will read the actual attribute.
.data will read the current value of that data item. If you have code which has changed the value (ie, $('#getMessage').data('sid',160)) that will be the current value.
The data() function stores data to a specific element
Store arbitrary data associated with the specified element and/or return the value that was set.
jQuery.data($('#element'), data);
On the other hand, attr() gets or sets attributes form the element.
$('div').attr('data-test', 'test');
<div data-test="test"></div>
as requested a working example..., notice that i can change the value of the data attribute without changing the actual attribute
console.log($('#getMessage').attr('data-sid'));
console.log($('#getMessage').data('sid'));
$('#getMessage').data('sid', 160);
console.log($('#getMessage').attr('data-sid'));
console.log($('#getMessage').data('sid'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="getMessage" data-sid="158">
<strong>Name</strong> : Rahul Kumar
<br>
<strong>Total </strong> : 25
<br>
</p>
This question already has answers here:
How to set file input value when dropping file on page? [duplicate]
(1 answer)
Dynamically set value of a file input [duplicate]
(4 answers)
How to set a value to a file input in HTML?
(10 answers)
Closed 9 years ago.
Note:
The answer(s) below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017.
See the answer in this question for details as well as a demo:How to set file input value programatically (i.e.: when drag-dropping files)?
I need to fill an HTML form with JavaScript to set the path of a file for upload it. The web that this form belongs to, already has a visual upload implemented, but
<form id="mobile_fileform">
<input type="file" style="height: 20px; width: 0px; opacity: 0; " id="mobile_fileselect1" multiple="" size="-17">
<input type="file" style="height: 20px; width: 0px; opacity: 0; " id="mobile_fileselect2" multiple="" size="-17">
<input type="file" style="height: 20px; width: 0px; opacity: 0; " id="mobile_fileselect3" multiple="" size="-17">
</form>
How can I set the path of the file in this form and how can I upload it using JavaScript?
Thanks for your help
The value property of input:file is read-only for security reasons. If you want to set it, you'll need to do it server-side.
As a result, what you're asking to do is not possible. Consider the implications: any webpage would be able to upload any file from someone's computer, so long as they knew the path.
My first question is:
- is it possible to copy from 1 file input data to another file input data?
what i mean is:
I have this input : <input type="file" name="fileinput1" />
Now I want to take what the user browse and copy the data to
<input type="file" name="fileinput2" />
Is that possible?
Second question, I have this element on my HTML input multiple="multiple"
it let me choose few files. Now I can see in the bottom that the names are getting together like this:
"img1" "img2" "img3" "img4"
Is there any way to separate this into few inputs? Like to write inputs with JavaScript and with the path to everyone of them, is that possible?
is it possible to copy from 1 file input data to another file input data?
No. File inputs are read only.
is there any way to separate this into few inputs?
No.