|
Hi ,
I have a string into clipboard (FirstName MiddleName Last Name). i want to paste this data into three different Textbox by a single paste in First Textbox.
ex . if i paste "Ravi Shankar Sharma"
then the data should appear like this
First Text box : Ravi
Second Text Box: Shankar
Third text box : Sharma
any one can help me
|
|
|
|
|
jQuery solution is pretty simples, but there is one weirdness, you cant read the value of the field until after it's been pasted, so I intoduce a short 1ms delay between paste, and trying to update the field:
$('#first').on('paste',function(e){
setTimeout(function(){
var text = $('#first').val().split(' ');
$('#first').val(text[0]);
$('#second').val(text[1]);
$('#third').val(text[2]);
},1)
});
Live example: http://jsfiddle.net/PjT28/[^]
I also don;t cover any of the multitude of error conditions (empty paste, paste without 3 names separated by a single space etc etc etc)
|
|
|
|
|
<html>
<head>
<title>Java Script - Capita Learning : ClipBoard Data </title>
<script type="text/javascript" >
function afterPaste(txt)
{
var T = window.clipboardData.getData('Text');
document.getElementById('Txt_Data2').value = T;
document.getElementById("Txt_Data3").value = T;
var len = T.length;
var n = T.indexOf(" ");
document.getElementById("Txt_Data2").value = T.substring(0,n);
T = T.substring(n+1,len);
len = T.length;
n = T.indexOf(" ");
document.getElementById("Txt_Data3").value = T.substring(0,n);
document.getElementById("Txt_Data4").value = T.substring(n+1,len);
}
</script>
</Head>
<body>
<p> On Paste event in java script
<p> <Input Type="Textbox" ID="Txt_Data" OnPaste="afterPaste(this.value)" >
<p> <Input Type="Textbox" ID="Txt_Data2" Name="Txt_Data2" >
<p> <Input Type="Textbox" ID="Txt_Data3" Name="Txt_Data3" >
<p> <Input Type="Textbox" ID="Txt_Data4" Name="Txt_Data4" >
</body>
</html>
|
|
|
|
|
hi,
I think this will work only in ie.what we can do for other browsers?
|
|
|
|
|
You could try putting Google Search to use........I am sure you could probably find something relevant in the time it took you to post that message.
|
|
|
|