473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Paste multiline text into several input fields

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
iv**@tda.no
Oct 2 '05 #1
6 6108
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.

Oct 2 '05 #2
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" <ad******@gmail.com> skrev i melding
news:11**********************@z14g2000cwz.googlegr 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.

Oct 2 '05 #3
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>

Oct 2 '05 #4
BTW if replace \n with \t you should be able copy to each cell on
single row

Oct 2 '05 #5
Figured it out. The following seem to work ok ;-)
iv**@tda.no

<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>
Oct 2 '05 #6
McA
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.


IE and Mozilla don't allow to paste multiline text in to regular input
field, if you do so, only first line will be inserted. Opera puts the whole
multiline string in, but replaces newline symbol(s) with two char 32.
I suggest to use textarea element istead first input.
Oct 2 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gotcha | last post by:
I have a little code to add multiple items to a shopping cart based page. This code works perfect, but it adds all of the info to the same input fields every time it loops. I need it to change...
6
by: Liam Gibbs | last post by:
Does anyone know how to make input fields smaller, using a smaller font? I want to know how to make my textboxes and such like the ones at http://www.gracenote.com/music/ , but reading teh code...
2
by: Chris | last post by:
Hi We are using style sheets to set the font of our labels and text boxes. This has been working great until we required a text box with a textmode of Multiline. The control picks up the...
3
by: Owen Richardson | last post by:
I have read several posts regarding formatting multiline text for rendering becuase vbCrLf needs to be converted to <br/tags, and i need to do the same. My question is the best way to achieve this...
14
by: Pythor | last post by:
Hi, I need to data from several input fields, and treat them as if they were all the same field. I'm not describing this well, so I'll give an example: I have a table like this: Name ...
6
by: dawnerd | last post by:
Hello everyone. I have a question, or problem if you will, that I'm sure someone knows the answer to. I have a database that stores information on a given user. The information is stored in a...
10
meenakshia
by: meenakshia | last post by:
hi forum:) i have a form in which i have four input fields for pieces to be entered and 4 fields for amount what i want is that the first pieces-t1 should be visible and rest three should not show...
2
by: King | last post by:
Is there any other way to define multiline text in a XML file: <Help><!]> </Help>
1
by: Phoumano Somvie | last post by:
I am trying to do some calculation with this form but some input fields are resulting NaN. Can anyone explain the error and a fix? Thanks <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.