Reputation: 377
I want to get values of inputs (type text) with selecting them with my mouse, and copy their values with one single move / click of my mouse
I have that inputs :
<input type="text" value="one" />
<input type="text" value="two" />
<input type="text" value="three" />
<input type="text" value="four" />
I want to copy (in my clipboard) the text of my inputs 1 & 2 & 3 by passing my mouse over them
Not just one input ... but multiple inputs by only one move of my mouse and after that I will do Ctrl-C
Upvotes: 0
Views: 193
Reputation: 135
Please try the following code, this might solve your problem
$('input[type=text]').mouseover(function() {
var abtest = '';
$('input[type=text]').each(function() {
abtest = abtest + ', ' + $(this).val();
});
if (abtest.indexOf(',') >= 0)
abtest = abtest.substring(1, abtest.len);
$('#lbltest').text(abtest);
SelectText('lbltest');
});
function SelectText(element) {
var doc = document,
text = doc.getElementById(element),
range, selection;
if (doc.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="text" value="one" />
<input type="text" value="two" />
<br>
<input type="text" value="three" />
<input type="text" value="four" />
<br>
<br>
<br>
<label id="lbltest">abtest</label>
Upvotes: 1