Jephta Posted December 28, 2020 Report Share Posted December 28, 2020 Hi all, i hope someone can help me out. I have a tabular search form with details form. I have implemented default values on the dropdowns in the search form. The defaults are set in the datapageready and beforeformsubmit events using localstorage, This works fine from the desktop chrome browser but not from my mobile phone also using chrome browser. Here is the code snippet: <script type="text/javascript"> document.addEventListener('DataPageReady', function (event) { if (typeof(Storage) !== "undefined") { if(localStorage.getItem("continent") !== null && localStorage.getItem("continent") !== "") { document.getElementsByName("Value2_1")[0].value = localStorage.getItem("continent"); } else { document.getElementsByName("Value2_1")[0].value = "1"; } } else { alert ("Sorry! No Web Storage support.."); } // stop for sometime if needed setTimeout(setCountry, 1000); }); function setCountry() { if (typeof(Storage) !== "undefined") { if(localStorage.getItem("country") !== null && localStorage.getItem("country") !== "") { document.getElementsByName("Value3_1")[0].value = localStorage.getItem("country"); } else { document.getElementsByName("Value3_1")[0].value ="1"; } } else { alert ("Sorry! No Web Storage support.."); } var event = new Event('change'); document.getElementsByName("Value3_1")[0].dispatchEvent(event); // stop for sometime if needed setTimeout(setLanguage, 1000); } function setLanguage() { if (typeof(Storage) !== "undefined") { if(localStorage.getItem("language") !== null && localStorage.getItem("language") !== "") { alert ("Language is already set in DataPageReady to " + localStorage.getItem("language")); document.getElementsByName("Value4_1")[0].value = localStorage.getItem("language"); } else { document.getElementsByName("Value4_1")[0].value = "1"; } } else { alert ("Sorry! No Web Storage support.."); } var event = new Event('change'); document.getElementsByName("Value4_1")[0].dispatchEvent(event); // stop for sometime if needed setTimeout(setCultureFeature, 1000); } function setCultureFeature() { if (typeof(Storage) !== "undefined") { if(localStorage.getItem("culturefeature") !== null && localStorage.getItem("culturefeature") !== "") { document.getElementsByName("Value5_1")[0].value = localStorage.getItem("culturefeature"); } else { document.getElementsByName("Value5_1")[0].value = "6"; } } else { alert ("Sorry! No Web Storage support.."); } var event = new Event('change'); document.getElementsByName("Value5_1")[0].dispatchEvent(event); } document.addEventListener('BeforeFormSubmit', function (event) { if (typeof(Storage) !== "undefined") { localStorage.setItem("continent",document.getElementsByName("Value2_1")[0].value); localStorage.setItem("country",document.getElementsByName("Value3_1")[0].value); localStorage.setItem("language",document.getElementsByName("Value4_1")[0].value); localStorage.setItem("culturefeature",document.getElementsByName("Value5_1")[0].value); } else { alert ("Sorry! No Web Storage support.."); } }); </script> Quote Link to comment Share on other sites More sharing options...
0 Vitalikssssss Posted December 29, 2020 Report Share Posted December 29, 2020 Hi @Jephta, I would recommend using standard Caspio features rather than custom code. You may consider approach of assigning default values described in this HowTo article: https://howto.caspio.com/datapages/datapage-components/setting-up-default-values/ Hope this helps. Regards, vitalikssssss Quote Link to comment Share on other sites More sharing options...
0 wimtracking2 Posted April 11, 2022 Report Share Posted April 11, 2022 @Jephta Did you have any success implementing this code? I am looking for something every similar. Quote Link to comment Share on other sites More sharing options...
0 Kurumi Posted April 15, 2022 Report Share Posted April 15, 2022 Hi @wimtracking2 - what is your workflow or expected result? Quote Link to comment Share on other sites More sharing options...
0 wimtracking2 Posted April 18, 2022 Report Share Posted April 18, 2022 Hi @Meekeee - I have a one-page submission form in which I would like to implement localstorage on (each field). In the past, I have used multi-page forms to save data as the user goes, but there is a lot of logic built into one long page, so I would like to save data to localstorage in case the user accidentally exits out of the page and has to return to it. Viewable here: Test Form • WIM Tracking Quote Link to comment Share on other sites More sharing options...
Question
Jephta
Hi all, i hope someone can help me out.
I have a tabular search form with details form.
I have implemented default values on the dropdowns in the search form.
The defaults are set in the datapageready and beforeformsubmit events using localstorage,
This works fine from the desktop chrome browser but not from my mobile phone also using chrome browser.
Here is the code snippet:
<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
if (typeof(Storage) !== "undefined") {
if(localStorage.getItem("continent") !== null && localStorage.getItem("continent") !== "") {
document.getElementsByName("Value2_1")[0].value = localStorage.getItem("continent");
} else {
document.getElementsByName("Value2_1")[0].value = "1";
}
} else {
alert ("Sorry! No Web Storage support..");
}
// stop for sometime if needed
setTimeout(setCountry, 1000);
});
function setCountry() {
if (typeof(Storage) !== "undefined") {
if(localStorage.getItem("country") !== null && localStorage.getItem("country") !== "") {
document.getElementsByName("Value3_1")[0].value = localStorage.getItem("country");
} else {
document.getElementsByName("Value3_1")[0].value ="1";
}
} else {
alert ("Sorry! No Web Storage support..");
}
var event = new Event('change');
document.getElementsByName("Value3_1")[0].dispatchEvent(event);
// stop for sometime if needed
setTimeout(setLanguage, 1000);
}
function setLanguage() {
if (typeof(Storage) !== "undefined") {
if(localStorage.getItem("language") !== null && localStorage.getItem("language") !== "") {
alert ("Language is already set in DataPageReady to " + localStorage.getItem("language"));
document.getElementsByName("Value4_1")[0].value = localStorage.getItem("language");
} else {
document.getElementsByName("Value4_1")[0].value = "1";
}
} else {
alert ("Sorry! No Web Storage support..");
}
var event = new Event('change');
document.getElementsByName("Value4_1")[0].dispatchEvent(event);
// stop for sometime if needed
setTimeout(setCultureFeature, 1000);
}
function setCultureFeature() {
if (typeof(Storage) !== "undefined") {
if(localStorage.getItem("culturefeature") !== null && localStorage.getItem("culturefeature") !== "") {
document.getElementsByName("Value5_1")[0].value = localStorage.getItem("culturefeature");
} else {
document.getElementsByName("Value5_1")[0].value = "6";
}
} else {
alert ("Sorry! No Web Storage support..");
}
var event = new Event('change');
document.getElementsByName("Value5_1")[0].dispatchEvent(event);
}
document.addEventListener('BeforeFormSubmit', function (event) {
if (typeof(Storage) !== "undefined") {
localStorage.setItem("continent",document.getElementsByName("Value2_1")[0].value);
localStorage.setItem("country",document.getElementsByName("Value3_1")[0].value);
localStorage.setItem("language",document.getElementsByName("Value4_1")[0].value);
localStorage.setItem("culturefeature",document.getElementsByName("Value5_1")[0].value);
} else {
alert ("Sorry! No Web Storage support..");
}
});
</script>
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.