- This topic has 5 replies, 2 voices, and was last updated 11 years, 4 months ago by SKnoxmn.
-
AuthorPosts
-
SKnoxmnMemberPreviously have been figuring out how to get data into a text field. And thats all good now.
I was looking at a Compass script that Wayne posted. In it he has a headingTxt, and a heading lable text.
Seems that when the script runs, its posting the data to the “fieldTxt”.
I’d like to know how to have my returned data post as text, rather than post the text into a text field.
Have I confused this quesstion enough?
SKnox
SKnoxmnMemberOK, I’ll try to gather my learning knowledge from many places at once.
Here’s what I have:
function findPosition()
{
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
function onSuccess(position)
{
$(‘#m1-Learning-textField1’).val(position.coords.latitude);
$(‘#m1-Learning-textField2’).val(position.coords.longitude);
$(‘#m1-Learning-textField3’).val(Math.round(position.coords.altitude));I have a textField on my form (textField7) where I would like the value that is calculated from the position.coords.latitude.
Trying to do follows:
function calcVel()
{
$(‘#m1-Learning-textField7’).val(Math.COS(RADIANS(position.coords.latitude))*(1037.5646));
}Basically I want to do some math against the “returned data” in the “textField1” but that data could be changing at different times. So I’m thinking that data is going to have to become a variable since it is…well… variable….
SKnox
Stu WadeMemberHi again,
You need to declare a global variable.
This means you need to tell the program about a new variable that is not bound inside a function… The syntax is
var myVariable;
The name myVariable is case sensitive and must start with a letter other than that it can be what you like as long as you stick to standard alphanumeric characters.
You should place the line at the beginning of the xxx_custom.js file
You then simply put the required value into the variable with a statement like
myVariable = some expression or value
SKnoxmnMemberHey again,
So I’ll make my var horVel;
and
horVel = (position.coords.latitude)
then,
function horVel()
{
$(‘#m1-Learning-textField7’).val(Math.COS(RADIANS(horVel))*(1037.5646));
}finally
onClick = horVel();
Sound about right? or again, am I at least in the ball park?
SKnox
Stu WadeMemberOnce again, the devil is in the detail …
You must make all variables unique and functions within the terminology of Javascript are variables … So yes, but call the function something else.
SKnoxmnMemberagain no love…
Im going to be reading up on this more. So far everything Im finding on this topic is relating to user input. or variables where you have set the value. Kind of a persistant value. Also seen some things on dynamically creating variables.
Im still having trouble finding a site that will explain how to use returned data from an event as the changing variable value.
Back to the ‘net’.
-SKnox
-
AuthorPosts