Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    creating and writing variable

    I am working on a javascript for my blackberry. I am trying to capture the latitude and longitude of that phone. I am able to get the coordinates in an alert box but am having a little trouble writing it to a form input field. Can anyone help me with this?
    Code:
    <!DOCTYPE html PUBLIC
        "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <title>GPS Testing</title>
        </head>
        <body>
        	<script type="text/javascript">
        	if(blackberry.location.GPSSupported){
        		document.write("Your device supports GPS locating");
    				blackberry.location.onLocationUpdate(window.alert("Latitude: " + blackberry.location.latitude + " Longitude: " + blackberry.location.longitude));
    				var lat = blackberry.location.latitude();
    				var lng = blackberry.location.longitude();
        		blackberry.location.refreshLocation();
    				document.write(lat);
    }
    	</script>
    
        </body>
    </html>
    I am only able to test with Blackberry.
    I was trying to create a couple of variables with the "var lat =" and var lng =".
    With this script I get the alert window and when I click ok it writes "Your device supports ..."
    Thanks for any help!

  • #2
    Regular Coder Krupski's Avatar
    Join Date
    Dec 2010
    Location
    United States of America
    Posts
    505
    Thanks
    39
    Thanked 47 Times in 46 Posts
    Quote Originally Posted by jmr3460 View Post
    I am working on a javascript for my blackberry. I am trying to capture the latitude and longitude of that phone. I am able to get the coordinates in an alert box but am having a little trouble writing it to a form input field. Can anyone help me with this?
    Trying to insert data into an input field? Easy.

    Code:
    <input type="text" id="input1" size="50" />
    
    <script type="text/javascript">
        var e = document.getElementById('input1');
        var text = 'This text inserted';
        e.value = text;
    </script>
    Is this what you want?
    "Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov

  • Users who have thanked Krupski for this post:

    jmr3460 (04-10-2011)

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts
    OK new code still not working:
    Code:
    <!DOCTYPE html PUBLIC
        "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <title>GPS Testing</title>
        </head>
        <body>
    <form>
    <input type="text" id="input1" size="10" /><br />
    <input type="text" id="input2" size="10" />
    </form>
    
    <script type="text/javascript">
    	if(blackberry.location.GPSSupported){
        		document.write("Your device supports GPS locating");
    				blackberry.location.onLocationUpdate(window.alert("Latitude: " + blackberry.location.latitude + " Longitude: " + blackberry.location.longitude));
        		blackberry.location.refreshLocation();
        var e = document.getElementById('input1');
        var f = document.getElementById('input2');
        //var text = 'This text inserted';
    				var text1 = blackberry.location.latitude;
    				var text2 = blackberry.location.longitude;
        e.value = text1;
        f.value = text2;
      }
    </script>
    </script>
        </body>
    </html>
    I am still not sure if my variables are correct.

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts
    My goal with this project is to insert the latitude and longitude into a database. I just need to get the variable from a javascript script to a form field. The code I have posted takes the lat lng information and inserts it into an alert. I would be very thankful to find out how to create a variable from the blackberry.location.latitude object value into a form field. The example that was given to me works by itself but when I try and create a variable from the blackberry code Nothing happens. I do not have a deadline or am not getting paid for this. This is for my personal use only. I am trying to let my blackberry be my time card. I have tried several apps and none of them are giving me what I want.
    Is there anyone out their that can help me with the variable thing.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,516
    Thanks
    77
    Thanked 4,379 Times in 4,344 Posts
    So *do* the values of lat and long then at least appear in the <form> fields, as you coded in message 3??

    If so, then you just need to change the HTML, not the JavaScript.

    If not, then try this page to see what happens:
    Code:
    <html>
    <body>
    <script type="text/javascript">
    if(blackberry.location.GPSSupported)
    {
        blackberry.location.refreshLocation();
        var lat = blackberry.location.latitude;
        var lon = blackberry.location.longitude;
        alert("GPS supported, latitude=" + lat + ", longitude=" + lon);
    }
    </script>
    </body>
    </html>
    Does *THAT* show the lat and long???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    jmr3460 (04-10-2011)

  • #6
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hey thanks for the reply. I just got up and saw it.
    Nothing happens with that code. It is wild how a little sleep helps in the reasoning process. I have new code is achieving my javascript goal.
    Code:
        	<script type="text/javascript">
        	  if(blackberry.location.GPSSupported){
    				document.write("<input type=\"text\" id=\"input1\" size=\"10\" value=\"" + blackberry.location.latitude + "\" />");
    				document.write("<input type=\"text\" id=\"input1\" size=\"10\" value=\"" + blackberry.location.longitude + "\" />");
        		blackberry.location.refreshLocation();
    }
    	</script>
    This piece of code puts the coordinates into the value of the text boxes. I am going to play around a little more with the idea of how Krupski suggested and see what happens their. Thanks for the help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •