Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split apart multiline text

Status
Not open for further replies.
Sep 27, 2001
179
AU
Hi

I want to be able to covert a block of text (an address)entered in a multiline text box.

Then take each line and place in it's own text box. So the first line will be '10 The Street', next line 'The City' etc

Can anyone suggest the best approach to do this. Would I use a regular expression to check for the existence of a carriage return?

Thanks

Rob



 

I would do as you suggest and split on the carriage return using regular expressions... or include a seperate text input for each line (and then combine them "behind the scenes" as needed using your server-side scripting environment).

Cheers,
Jeff

 
I would do the second thing Jeff mentions, which is including a separate text box for each line and combine them later if you have to. But if you still want to split a multiline box, It'd be something like this:
Code:
var myArray = document.formName.fieldName.value.split(/\n/);

Adam

¡ph ¥0u c4n r34d d¡5 ¥0u n33d 70 g37 l4¡d
 
Hi

Thanks for your feedback, I have managed to get the basics of the script working now.

The reason I am doing it this way is that the users wish to be able to cut and paste an address from another source, e.g. an email.

The purpose of the script is to then take what they have and try and pre-populate the separate address text boxes that the database expects.

Rob
 

I would be very, very, wary of doing this, as there are so many different address types, you would not know what line should be in which field.

For example, if you had text boxes for "street 1", "street 2", "city", and "county", and the address was:

Flat 41
78 Some Street
Norwich
Norfolk

That would work just fine. But if your address didn't have a flat number, then you would end up with "Norfolk" being the city - which is clearly wrong.

One of my biggest gripes is to do with websites that don't let me enter my address as it is. IMHO, you should use a multi-line text-field and store the data back-end that way, OR have the individual fields on the page to start with. Trying to auto-parse addresses and get the output correct in all cases is impossible.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Hi Dan

I am aware of the problems with this, and I won't normally do this. The database I am using holds the data in separate columns, which I prefer as a method as it means that you can do more with the address data when it comes to reporting & filtering.

But the client has a current system that uses a multiline text box. So I am trying to help the user a little even if some address data will go to the wrong fields.

I will be recommending to the client that they abandon the idea altogether but for the moment I have a workable mock up.

Thanks

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top