sangeetha k

sangeetha k

  • NA
  • 207
  • 51.6k

Copy to clipboard with label value followed by a ; and text

Feb 13 2019 12:02 AM
 
I wish to copy contents to a clipboard in this format 
LAbel : input textbox value 
 
but the jquery which i found seems to give this format
Label
text
label 
text
 Pls someone give a appropriate way to   sought out this.
 
 #html code  along with jquery .
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CopyClip.aspx.cs" Inherits="CopyClip.CopyClip" %>
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
textarea, select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
<title></title>
<script src="Scripts/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function () {
$("#copyclick").click(function () {
var id = $(this).attr('id');
var el = document.getElementById('div1');
var range = document.createRange();
range.selectNodeContents(el);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
document.execCommand('copy');
})
})
</script>
</head>
<body>
<div id="div1">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="your name..." />
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="your last name...." />
<label for ="country">Country</label>
<select id="country" name="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
</select>
<label for ="myInput">Textarea</label>
<input type="text" value="Hello World" id="myInput">
<label for="textarea">MultilineArea</label>
<textarea rows="5" cols="100" id="textarea"></textarea>
<button id="copyclick"onclick=" myFunction()">Copy text</button>
</div>
</body>
</html>

Answers (10)