- This topic has 10 replies, 4 voices, and was last updated 11 years ago by support-octavio.
-
AuthorPosts
-
brianrayMemberi keep getting the message that “cant find verables”
im sure its somthing stupid, can some body help me, i have put the code in.
/////
///Save Data Function
/////
function saveData(){
//Our text field datavar phone1 = $(‘#m1-MSDS_v2-phone1’).val();
var phone2 = $(‘#m1-MSDS_v2-phone2’).val();
var phone3= $(‘#m1-MSDS_v2-phone3’).val();
var name = $(‘#m1-MSDS_v2-name’).val();
var message = $(‘#m1-MSDS_v2-message’).val();//Test to see if the browser supports localStorage
if(localStorage){
//Set the name, age and colour items
localStorage.setItem(‘phone1’ );
localStorage.setItem(‘phone2’);
localStorage.setItem(‘phone3’);
localStorage.setItem(‘name’);
localStorage.setItem(‘message’);
alert(‘Save completed’);
}
//Alert the user to upgrade their browser
else {
alert(‘Local storage not supported. Please get a proper browser’);
}}
/////
///Get Data Function
/////
function getData(){
//Create an empty results string
var strResults = ”;
//Test to see if the browser supports localStorage
if(localStorage){
//Declare the item values as variables
var phone1 = localStorage.getItem(‘phone1’);
var phone2 = localStorage.getItem(‘phone2’);
var phone3 = localStorage.getItem(‘phone3’);
var name = localStorage.getItem(‘name’);
var message = localStorage.getItem(‘message’);//Build the results into the results string
strResults += ‘saved data ‘
+’Primary phone number ‘
+ phone1
+ ‘ secondry phone number ‘
+ phone2
+ ‘ third phone number’
+ phone3
+ ‘ Your name is ‘
+ name
+ ‘ Your message is ‘
+ message
+ ”;
//Append the body with the results
$(‘#m1-MSDS_v2-textField3’).append(strResults);
}
//Alert the user to upgrade their browser
else {
alert(‘Local storage not supported. Please get a proper browser’);
}}
/////
///Document Ready
/////
$(document).ready(function(){
//Bind events to the buttons to fire off the functions
$(‘Save’).bind(‘click’ , saveData);
$(‘Get’).bind(‘click’ , getData);
});///RED alert—–
function redAlert(){
//get gps location—funtion–
function getLocation() {
navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
function foundLocation(position) {var lat = position.coords.latitude;
var long = position.coords.longitude;}
}function noLocation() {
var lat = ‘no location data’;
var long = ‘no location data’;
}
}//Create an empty results string
var strResults = ”;
//Test to see if the browser supports localStorage
if(localStorage){
//Declare the item values as variables
var phone1 = localStorage.getItem(‘phone1’);
var phone2 = localStorage.getItem(‘phone2’);
var phone3 = localStorage.getItem(‘phone3’);
var name = localStorage.getItem(‘name’);
var message = localStorage.getItem(‘message’);//Build the results into the results string
strResults += ‘Red`Alert ‘
+’My location is ‘
+ “LAT : “+lat +”, LONG : “+long
+ ‘ My name is ‘
+ name
+ ‘ Your message is ‘
+ message
+ ”;
//Append the body with the results
$(‘#m1-MSDS_v2-textField4’).append(strResults);
// send SMS to primary phone number
String messageToSend = (“#m1-MSDS_v2-textField4”);
String number = “phone1”;SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
// send SMS to second phone number
String messageToSend = “$(‘#m1-MSDS_v2-textField4’)”;
String number = “phone2”;SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
// send SMS to third phone number
String messageToSend = “$(‘#m1-MSDS_v2-textField4’)”;
String number = “phone3″;SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
// vibarate when sms sent–
start() duration= 2500 stop()//—Repeat at 3 minute intervals
}
function amberAlert()
//get gps location—funtion–
function getLocation() {
navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
function foundLocation(position) {var lat = position.coords.latitude;
var long = position.coords.longitude;}
}function noLocation() {
var lat = no location data;
var long = no location data;
}
}//Create an empty results string
var strResults = ”;
//Test to see if the browser supports localStorage
if(localStorage){
//Declare the item values as variables
var phone1 = localStorage.getItem(‘phone1’);
var message2 = $(‘#m1-MSDS_v2-textField5’)//Build the results into the results string
strResults += ‘Amber Alert ‘
+’My location is ‘
+ “LAT : “+lat +”, LONG : “+long
+ ‘ My name is ‘
+ name
+ ‘ Your message is ‘
+ message2
+ ”;
//Append the body with the results
$(‘#m1-MSDS_v2-textField5’).append(strResults);
// send SMS to primary phone number
String messageToSend = “$(‘#m1-MSDS_v2-textField5’)”;
String number = “phone1″;
}function cancelAlert()
{
//get gps location—funtion–
function getLocation() {
navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
function foundLocation(position) {var lat = position.coords.latitude;
var long = position.coords.longitude;}
}function noLocation() {
var lat = no location data;
var long = no location data;
}
}//Create an empty results string
var strResults = ”;
//Test to see if the browser supports localStorage
if(localStorage){
//Declare the item values as variables
var phone1 = localStorage.getItem(‘phone1’);
var phone2 = localStorage.getItem(‘phone2’);
var phone3 = localStorage.getItem(‘phone3’);
var name = localStorage.getItem(‘name’);//Build the results into the results string
strResults += ‘Cancel Alert Status’
+’My location is ‘
+ “LAT : “+lat +”, LONG : “+long
+ ‘ My name is ‘
+ name
+ ‘ Please Cancel Alert Status’
+ ”;
//Append the body with the results
$(‘#m1-MSDS_v2-textField6’).append(strResults);
// send SMS to primary phone number
String messageToSend = “$(‘#m1-MSDS_v2-textField6’)”;
String number = “phone1”;SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
// send SMS to second phone number
String messageToSend = “$(‘#m1-MSDS_v2-textField6’)”;
String number = “phone2”;SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
// send SMS to third phone number
String messageToSend = “$(‘#m1-MSDS_v2-textField6’)”;
String number = “phone3″;SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
// vibarate when sms sent–
start() duration= 2500 stop()
}//—Vibrate funtion——————————–
timerId = -1;
frequency = 1; //seconds
isRunning = false;
showNoCordovaMsg = true;
VIBRATE_DURATION = 250; //millisecondsfunction start() {
if (showNoCordovaMsg && !phoneui.cordovaAvailable ()) {
alert(‘Vibrate feature is only available for \nHTML5 apps. ‘);
showNoCordovaMsg = false;
}
if (isRunning) { //restart
stop();
start();
return;
}
isRunning = true;
frequency = $(‘select[name=”frequency”]’).val()
timerId = setInterval(
function() {
if (phoneui.cordovaAvailable ()){
navigator.notification.vibrate(VIBRATE_DURATION);
}
},
frequency * 1000 + VIBRATE_DURATION);
}function stop() {
if (!isRunning) return;isRunning = false;
clearInterval(timerId);
}
nvtsMemberHello,
Without seeing the project and setting alerts to read the variables at certain process, here is my thoughts.
In the past when I used a _underscore in a screen name it had some issues. I am not sure if it really was the underscore, but at the time I changed this It seemed to work.
Using the same variable name for getting the screen input values and then on reading the localstorage values to that same name and throughout the other functions might be causing an issue also.
Just what I can see while browsing the code.
Cheers…
support-octavioMemberHi,
From what I can see you are not assigning a value for your localstorage items:
localStorage.setItem('phone1' ); localStorage.setItem('phone2');
Try with:
localStorage.setItem('phone1',phone1); localStorage.setItem('phone2',phone2);
And so on. Hope this make sense.
Let me know if you need further assistance.
nvtsMemberGood catch octavio,
That is why I like to use a different variable name then it seems easier to catch.
Cheers…
brianrayMemberHi Guys,
thanks for your help, took both lots of advice and applied it.
now in test center it shows that local storage has activated ( but i can see whats in it)
I’m trying to conferm the data stored with get.localStorage and display in a text feild on the next page (multipage widgit) I have no display.
i have cut the peice of code from the main block becouse there is a praseing error further down.
Also do i need to bind the keys ( the last piece of code?/////
///Save Data Function
/////
function saveData(){
//Our text field datavar primaryNumber = $(‘#m1-MSDS2-primaryNumber’).val();
var secondryNumber = $(‘#m1-MSDS2-secondryNumber’).val();
var thirdNumber = $(‘#m1-MSDS2-thirdNumber’).val();
var client = $(‘#m1-MSDS2-client’).val();
var messageData = $(‘#m1-MSDS2-messageData’).val();//Test to see if the browser supports localStorage
if(localStorage){
//Set the name, age and colour items
localStorage.setItem(‘phone1’,primaryNumber);
localStorage.setItem(‘phone2’,secondryNumber);
localStorage.setItem(‘phone3’,thirdNumber);
localStorage.setItem(‘name’,client);
localStorage.setItem(‘message’,messageData);
alert(‘Save completed’);
}
//Alert the user to upgrade their browser
else {
alert(‘Local storage not supported. Please get a proper browser’);
}}
/////
///Get Data Function
/////
function getData(){
//Create an empty results string
var strResults = ”;
//Test to see if the browser supports localStorage
if(localStorage){
//Declare the item values as variables
var phone1 = localStorage.getItem(‘phone1’);
var phone2 = localStorage.getItem(‘phone2’);
var phone3 = localStorage.getItem(‘phone3’);
var name = localStorage.getItem(‘name’);
var message = localStorage.getItem(‘message’);//Build the results into the results string
strResults = ‘saved data ‘
+’Primary phone number ‘
+ phone1
+ ‘ secondry phone number ‘
+ phone2
+ ‘ third phone number’
+ phone3
+ ‘ Your name is ‘
+ name
+ ‘ Your message is ‘
+ message
+ ”;
//Append the body with the results
$(‘#m1-MSDS2-textField3’).append(strResults);
}
//Alert the user to upgrade their browser
else {
alert(‘Local storage not supported. Please get a proper browser’);
}}
/////
///Document Ready
/////
$(document).ready(function(){
//Bind events to the buttons to fire off the functions
$(‘Save’).bind(‘click’ , saveData);
$(‘Get’).bind(‘click’ , getData);
});
nvtsMemberBrian,
Your code for retrieving the local storage looks good, except I would use different variable names myself.
Just add a alert to display the variable contents just after getting them to make sure you have the data.
For sending a variable to a second screen, I put the code for this in the postPageTransition section.
phoneui.postPageTransition = function(newScreenId) {
if (newScreenId== ‘#m1-secondscreen’) {
//forwards the local storage item to the second screen
var passRetrievedObject = retrievedObject;
$(‘#m1-secondscreen-text1’).text(passRetrievedObject);
}}
You can either get the items in the above function and then pass it to the second screen or read to variables for use in other screens as you are doing now.
Cheers…
brianrayMemberthanks , but didnot work, i think its in the way im trying to get the varibals to display.
Not real good at Java but lerning fast.we will be purchasing Mobi one manly becouse of the help i’m getting from you guys
thanks againBrian
nvtsMemberBrian,
Look and download the sample login script that I posted a week back. It is using the entered data from one screen and then displaying the user name on the second screen. It is not using local storage variables, but it gives you an idea.
http://www.genuitec.com/support-genuitec/viewtopic.php?f=8&t=6406&hilit=login
Did you get your app to show an alert of the data after getting it from local storage. This is a first step. Then try passing it to another screen and using in your other code. Have you tried looking at the Inspect Element/Resources and see what is in you local storage?
Cheers…
brianrayMemberHi NTVS.
Yes i have the alert working fine the get localStorage works fine there it when i try to build it into a string and display it in a text area nothing happens,
the error is
ERROR: undefined: Object [object Object] has no method ‘value’
Stack:
TypeError: Object [object Object] has no method ‘value’
at getData (http://127.0.0.1:9090/get/cc4214704b3749f59f11d49704e2ac99/MSDS2_custom.js:114:27)
at eval (eval at <anonymous> (http://127.0.0.1:9090/get/cc4214704b3749f59f11d49704e2ac99/MSDS2.js:38:31), <anonymous>:2:1)
at m1Design.actions.action1 (http://127.0.0.1:9090/get/cc4214704b3749f59f11d49704e2ac99/MSDS2.js:38:57)
at runUserCode (http://127.0.0.1:9090/get/cc4214704b3749f59f11d49704e2ac99/res/phoneui.js:1493:16)
at doClick (http://127.0.0.1:9090/get/cc4214704b3749f59f11d49704e2ac99/res/phoneui.js:2073:6)
at HTMLDivElement.<anonymous> (http://127.0.0.1:9090/get/cc4214704b3749f59f11d49704e2ac99/res/phoneui.js:2205:17)
at HTMLDivElement.v.event.dispatch (http://127.0.0.1:9090/get/cc4214704b3749f59f11d49704e2ac99/res/jquery-1.8.3.min.js:2:38053)
at HTMLDivElement.o.handle.u (http://127.0.0.1:9090/get/cc4214704b3749f59f11d49704e2ac99/res/jquery-1.8.3.min.js:2:33916) TypeError: Object [object Object] has no method ‘value’ cordova-2.9.0.js:5639getData is the function
my code isfunction saveData(){
//Our text field data and check primary number is filled invar primaryNumber = $(‘#m1-MSDS2-primaryNumber’).val();
//if Primary phone number is empty
if($(“#m1-MSDS2-primaryNumber”).val()==”){
alert (‘WARNING! Primary Phone number must be filled in for RED ALERT’);
return false;
}
var secondryNumber = $(‘#m1-MSDS2-secondryNumber’).val();
//if second phone number is empty
if($(“#m1-MSDS2-secondryNumber”).val()==”){
alert (‘WARNING! Second Phone number must be filled in for AMBER ALERT’);
return false;
}
var thirdNumber = $(‘#m1-MSDS2-thirdNumber’).val();
var client = $(‘#m1-MSDS2-client’).val();
// If Client ID is empty
if($(“#m1-MSDS2-client”).val()==”){
alert (‘WARNING! Client ID must be filled in for TRACKING’);
return false;
}
var messageData = $(‘#m1-MSDS2-messageData’).val();//Test to see if the browser supports localStorage
if(localStorage){
//Set the name, age and colour items
localStorage.setItem(‘telep1’,primaryNumber);
localStorage.setItem(‘telep2’,secondryNumber);
localStorage.setItem(‘telep3’,thirdNumber);
localStorage.setItem(‘iden’,client);
localStorage.setItem(‘data’,messageData);
alert(‘Save completed’+’ phone 1 ‘+primaryNumber +’ phone2 ‘+secondryNumber+’phone 3 ‘+thirdNumber+ ‘ client ID ‘+client+’ message ‘+messageData);
}//Alert the user to upgrade their browser
else {
alert(‘Local storage not supported. Please get a proper browser’);
}}
function getData(){
//Create an empty results string
var strResults = ”;
//Test to see if the browser supports localStorage
if(localStorage){
//Declare the item values as variables
var phone1 = localStorage.getItem(‘telep1’);
var phone2 = localStorage.getItem(‘telep2’);
var phone3 = localStorage.getItem(‘telep3’);
var name = localStorage.getItem(‘iden’);
var message = localStorage.getItem(‘data’);
alert(‘Get completed’+’ ph 1 ‘+phone1 +’ ph2 ‘+phone2+’ph 3 ‘+phone3+ ‘ client ID ‘+name+’ message ‘+message);
}
//Build the results into the results string
strResults = ‘saved data ‘+’ Primary phone number ‘+phone1+ ‘ secondry phone number ‘+phone2+’ third phone number ‘+ phone3+’ Your name is ‘+name+’ Your message is ‘+message;
//Append the body with the results
//$(‘#m1-MSDS2-textField3’).append(strResults);var text = $(strResults).val(); // global variable
$(‘#m1-MSDS2-textField1’).value(text);
}I beleave the problem is were im trying to build the string,
the guy sitting next to me is using the same code and it works fine < that is giving me the sh!!$2’s>
how do i add a zip file here??
MrBeanMemberCan it be that simple that on the first run of the program there is no data stored in local storage? Then all values will be undefined / null and needs to be handled.
Have you tried running the code in the emulator, hitting F12 bringing up the Chrome debugger, set a breakpoint and inspect the values? Single step (F10) the script until you get an exception and it should be a peace of cake to fix the problem.
support-octavioMemberHi brianray,
>ERROR: undefined: Object [object Object] has no method ‘value’
$('#m1-MSDS2-textField1').value(text);
Please change value for val. Let us know how it goes for you.
-
AuthorPosts