Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Paste multiline text into several input fields

Reply
Thread Tools

Paste multiline text into several input fields

 
 
Iver Erling Årva
Guest
Posts: n/a
 
      10-02-2005
I am looking for a way to let the users copy e.g. a multi-line address from
a textfile and paste it into a webpage where there is one input field for
each address line in such a way that not only the first line is pasted, but
instead the program automatically jumps to the next field and put line 2 in
there and so on.

Can this be done? I tried with onkeydown to check for event.keyCode == 13,
but it doesn't seem to work with paste.

Brgds
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
slyi
Guest
Posts: n/a
 
      10-02-2005
you could put an onchange event on your top input box and use the split
function on each '\n' (if exists inside the pasted text) and loop
through your splited text array and place the element text into each of
your input boxs.

 
Reply With Quote
 
 
 
 
Iver Erling Årva
Guest
Posts: n/a
 
      10-02-2005
That doesn't seem to work unfortunately, as the pasted text seem to have
been stripped for anything after the first \n at that point... I need a way
to pick up the entire text from the clipboard prior to the actual paste.e.g.
when the ctrl-v is pressed.


"slyi" <(E-Mail Removed)> skrev i melding
news:(E-Mail Removed) oups.com...
> you could put an onchange event on your top input box and use the split
> function on each '\n' (if exists inside the pasted text) and loop
> through your splited text array and place the element text into each of
> your input boxs.
>



 
Reply With Quote
 
slyi
Guest
Posts: n/a
 
      10-02-2005
try
<html >
<head>
<title>Untitled Page</title>
<script language="javascript">
function pasteall(){
allrows = window.clipboardData.getData('Text').split('\n');
for (var i=0;i<allrows.length;i++){
textrow='Text'+(i+1);
document.getElementById(textrow).innerText=allrows[i]

}
}
</script>
</head>
<body>
<input type=text id="Text1" onpaste="pasteall()" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Text3" type="text" />
<br />
<input id="Text4" type="text" />

</body>
</html>

 
Reply With Quote
 
slyi
Guest
Posts: n/a
 
      10-02-2005
BTW if replace \n with \t you should be able copy to each cell on
single row

 
Reply With Quote
 
Iver Erling Årva
Guest
Posts: n/a
 
      10-02-2005
Figured it out. The following seem to work ok
(E-Mail Removed)

<html>
<head>
<title>Test</title>
<script type=text/javascript>
function chkKey(){
tb = document.all["tb"]
var cbdata=window.clipboardData.getData("text");
cbd=cbdata.split("\n");
for (i=1;i<cbd.length;i++){
if (tb[i]) tb[i].value=cbd[i];
}
}
</script>
</head>

<body onload="form.T1.focus();">
<form name='form'>
<p>
<input id="tb" type="text" name="T1" size="20" onbeforepaste='chkKey();'>
<input id="tb" type="text" name="T2" size="20">
<input id="tb" type="text" name="T3" size="20">
</p>
</form>
</body>
</html>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy and Paste text in the Web page fields Sindhu Up Ruby 0 04-16-2009 01:09 PM
RDOC: several related modules in several C files Victor \Zverok\ Shepelev Ruby 3 03-16-2007 04:15 PM
how to define a variable to hold a multiline text input in perl from html multiline textbox dale zhang Perl Misc 8 11-30-2004 06:53 AM
Problem in CRLF in multiline fields Jack Wright ASP .Net 1 04-21-2004 05:00 AM
how to limit user input into the multiline text box???? cw ASP .Net 1 06-27-2003 11:57 AM



Advertisments