Javascript :: Paste clipboard to textarea - javascript

<!DOCTYPE html>
<html>
<body>
<form action=# method=post name=test>
<textarea name=numb id=numb rows=4 cols=50></textarea>
<input type=submit>
</form>
<script>
window.onload=function(){
document.getElementById("numb").value = window.clipboardData.getData('Text');
}
</script>
</body>
</html>
Title is pretty much self explanitory... I want to be able to paste the clipboard to the textarea onload... seems like a simple task but for some reason it's not working :/

That seems like a huge security issue if your javascript could access users clipboard right of the bat on onLoad :) So at the moment that can't be done directly via javascript. Maybe you should think alternative routes to that problem, like guiding people how to paste to that field e.g. via keyboard shortcuts.

Related

something like "http://test:<a b>" is not getting displayed in text area in IE

Anything given inside a tag is not getting displayed in a particular text area in IE.
example : http://test:
Do you mean you wrote exactly http://test: and it is not displaying the text inside the tag? On my side it is displaying in IE 11.
Sample code:
<!DOCTYPE html>
<html>
<head>
<script>
function add_txt()
{
document.getElementById("t_area").value = "http://test:<a b>";
}
</script>
</head>
<body>
<textarea rows="4" cols="50" id="t_area">
</textarea>
<input type="button" value="add text" onclick="add_txt()">
</body>
</html>
Output:
It was recongnized as text so it can be displayed. If you try to add HTML inside textarea then it will not going to display. this is the behavior with all the browsers not just with IE.
So if you try to add a text it will surely display it.
You can try to make a test with above code. If your issue still persist then try to provide a sample code to produce the issue. I will try to make a test with it on my side.

Google Apps Script Textarea

I have the following basic code to attempt changing the value of the textarea element. Using standard HTML works fine; however, using Google Apps Script, it will not work. There will be more to the program which will include additional lines via \n so a standard input tag can't be used - this is just the basic piece in which I need to populate text within the element. Does anyone know if this is possible with GAS? Note, only wanting to use the HTML file, not pure GAS JavaScript.
<!DOCTYPE html>
<base target="_top">
<button id=calc>test</button>
<textarea id=t></textarea>
<script>
document.getElementById("calc").onclick=function(){
document.getElementById("t").value="test";
}
</script>
looks like you forgot to put "calc" and "t" inside quatation marks like this - "id_of_an_element"
When I used Visual Code to check if it works in pure HTML it fixed it, but in Google Apps Script it didn't
I tested the below code in Google Apps Script and it works, I hope it helps
<!DOCTYPE html>
<html lang="en">
<body>
<base target="_top">
<button id="calc">test</button>
<textarea id="t">my text area inital value</textarea>
<script>
document.getElementById("calc").onclick=function(){
document.getElementById("t").value="test";
}
</script>
</body>
</html>

jQuery copy text into my clipboard from text of texarea

I have a textarea and I want When I move over text area it will show button and when I click this button it will copy text of text area into my clipboard. Just like mediafire.com. So, what can i do that. I tried to find some solution but it not helpful for me.
Thank.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<textarea id="myid">My text here</textarea>
</body>
</html>
I think it's a flash based with some javascript solution like this one :
https://github.com/zeroclipboard/zeroclipboard
My guess is that you can't access hardware like keyboard with javascript.
Started the search here and found http://www.steamdev.com/zclip

JQuery - placing the cursor at the end of a textarea when it is focused on

First, some of you may notice that I reposted this question after deleting it. This is because it was mistakenly marked as a duplicate by someone who didn't bother to check - the question he linked to was about an <input> element; that solution does not work for textareas.
Anyway, consider the following code:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function caek() {
$('textarea[name=txt1]').val("cake");
$('textarea[name=txt1]').focus();
}
</script>
</head>
<body>
<div id="bar"></div>
<form name="frm1" id="cake">
<textarea name="txt1"></textarea>
</form>
<input type="button" value="Activate"
onclick="caek()">
</body>
</html>
When you run that, you will notice that the cursor is pushed to the start of the textarea, before the text. How can I make it come after all the text, at the end of the textarea? A non-inline solution would be optimal, but anything will do.
And a standalone solution (no plugins etc) would be perfect.
This is working for me.
function caek() {
txtArea = $('textarea[name=txt1]');
txtArea.val("cake");
txtArea.focus();
tmpStr = txtArea.val();
txtArea.val('');
txtArea.val(tmpStr);
}
This works.
$ta.text($ta.text()).focus()
Demo: http://jsfiddle.net/elclanrs/WWsBa/
You can use the rangyinputs jQuery plugin to do this in a cross platform way.
There's a demo here:
http://rangyinputs.googlecode.com/svn/trunk/demos/textinputs_jquery.html
Set the start and end to the same number and it'll set the cursor to that point (though it doesn't focus the textarea, so you have to tab into it to see the effect). In your case, you'd want to set it to the length of the text.

Submitting a HTML form in and onload function

I want send a form as soon as the page is loaded. All variables in the form are written dynamically and there is no button for submitting.
Does following JS script work in all browsers ?
<script type='text/javascript'> window.onload = function(){ window.document.forms[0].submit(); }; </script>
I doubt window.onload will work in all without any problems.
Thanks in advance...
If you're worried about compatibility in all browsers, how about using jQuery's ready function?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
window.document.forms[0].submit();
});
</script>
Whilst I would agree that Ken's answer is perfectly acceptable, I don't believe it is correct to include a full-fat JS library just for its .ready() functionality.
For what it's worth, I'd recommend docReady. The size of docReady is 322 bytes gzipped (548 bytes uncompressed).
docReady(function() {
window.document.forms[0].submit();
});
I love jQuery, and I'd even say that there's not much of a perf impact in Ken's answer because it's likely that, if you're using the Google CDN, you've probably already downloaded it during your time on that site or others. But still, it's an unnecessary overhead on what should be a simple page IMO.
Don't use the window.onload (I mean, you can, but is easier/ more logical to do it differently). What you should do is print the form in a hidden div tag, assign an id to the submit button and then use javascript to 'click' it. Here is an example:
<div style="display: hidden;">
<form action="page/site" method="get/post">
<input type="hidden" name="name" value="value" />
<input type="submit" id="formButton" />
</form>
<script language="javascript">
document.getElementById("formButton").click();
</script>
</div>
I hope that helps.

Categories