Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# parse out text typed in one text box into two separate text boxes

Posted on 2008-10-20
Medium Priority
288 Views
I have a text box that users paste GPS cordinates into.  They enter :
Latitude: 42.079964  /  Longitude: -71.869398
into field "GPSCOORDINATES".  I would like it parsed out into two separate fields : Latitude & Longitude.
any ideas ?

Regards,
Mark
0
Question by:drelinger
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 16

Expert Comment

ID: 22759502
you can split it into an array

arrayVairable = Split(FormFieldWithGPS, '/')

this should give you a 2 array variable then you would acccess it like this:

Lattitude = arrayVariable[0]
Longitude =  arrayVariable[1]

0

LVL 16

Accepted Solution

sh0e earned 2000 total points
ID: 22759584

``````<script>
function parseGPS(gps_string){
matches = gps_string.match('Latitude: (-?[0-9]+\\.[0-9]+)  /  Longitude: (-?[0-9]+\\.[0-9]+)');
if(matches == null || matches.length != 3){
}
else{
var latitude = matches[1];
var longitude = matches[2];
}
}
</script>

<input type="button" value="grab GPS" onClick="parseGPS(document.getElementById('GPSCOORDINATES').value);"></input>
<input type="text" id="GPSCOORDINATES"></input>
``````
0

LVL 82

Expert Comment

ID: 22759587
try:
``````Dim str
str="Latitude: 42.079964  /  Longitude: -71.869398"
data = Split(str,"/")
data(0)=split(trim(data(0))," ")
data(1)=split(trim(data(1))," ")
Dim latitude,longitude
If "LATITUDE" = Left(Trim(UCase(data(0)(0))),8) Then
latitude = data(0)(1)
longitude= data(1)(1)
Else
latitude = data(1)(1)
longitude= data(0)(1)
End If
Response.Write( "Lat: " & latitude )
Response.Write( "Long:" & longitude )
``````
0

Author Closing Comment

ID: 31507884
I think all of the answers would work, but I felt this solution was the best.  Thank you.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
###### Suggested Courses
Course of the Month9 days, 9 hours left to enroll