- This topic has 2 replies, 2 voices, and was last updated 10 years, 9 months ago by living.horses.
-
AuthorPosts
-
living.horsesMemberHi,
I am including a calculator in my app, and I want to be able to provide the results in either lb Pounds, or kg Kilograms.
I have the java script working for both, but I would like just one set of input fields, with the results dependent on which radio button the user selects.ie if user selcets radio button for inches & pounds, they can enter measurements in inches, press ‘calculate’ and have the results show up in Pounds. The same for if the user selects the centimetres & kilograms radio button.
My javascript thus far works for the individual results kg or lb and is as follows;
function calculatekg() {
var girth1_value = document.getElementById(‘m1-weightcalc-girth1’).value;
var length1_value = document.getElementById(‘m1-weightcalc-length1’).value;
var unit = ” kg”;
document.getElementById(‘m1-weightcalc-resultkg’).value = (girth1_value*length1_value*girth1_value*0.000254).toFixed(2) + unit;
}/**
* Notification that the page’s HTML/CSS/JS is about to be loaded.
* Perform custom logic here, f.e. you can cancel request to the server.
* @param {String} targetScreenId
* @returns {boolean} true to continue loading; false to halt loading
*/
phoneui.prePageLoad = function(targetScreenId) {
// add custom pre-load code here
// return false to terminate page loading, this cancels transition to page as well
return true;
}/**
* Called when document is loaded.
*/
phoneui.documentReadyHandler = function() {
}function calculatelb() {
var girth1_value = document.getElementById(‘m1-weightcalc-girth1’).value;
var length1_value = document.getElementById(‘m1-weightcalc-length1’).value;
var unit = ” lb”;
document.getElementById(‘m1-weightcalc-resultlb’).value = (girth1_value*length1_value*girth1_value/300).toFixed(2) + unit;
}/**
* Notification that the page’s HTML/CSS/JS is about to be loaded.
* Perform custom logic here, f.e. you can cancel request to the server.
* @param {String} targetScreenId
* @returns {boolean} true to continue loading; false to halt loading
*/
phoneui.prePageLoad = function(targetScreenId) {
// add custom pre-load code here
// return false to terminate page loading, this cancels transition to page as well
return true;
}/**
* Called when document is loaded.
*/
phoneui.documentReadyHandler = function() {
}I am VERY new to java script, and i have put the above together with trial and error, adding rounding & units to it, until it worked. I am happy to learn, and willing to play around with it.
I am still searching through the web for examples, where I can try components to make this work, but I think it will be a little more complicated than the simple functions I am using thus far.
Thank you in advance for any input
🙂
Attachments:
You must be logged in to view attached files.
support-octavioMemberHi living.horses,
You need a function that check the radiogroup’s value, then use this value to know what function needs to be executed, f.e.
function checkRadioValues(){ var radioSelected = $('input[name="radio-group1"]:checked').val(); if(radioSelected=="radio1"){ function1(); } else{ function2(); } }
And your functions would be the ones that you already have. Since you are not using a button you can call this function when user clicks on radiobuttons setting the On click function as Run Javascript code. See screenshot:
See attachment radioConfig.pngAttachments:
You must be logged in to view attached files.
living.horsesMemberthank you, i will give it a go 🙂
-
AuthorPosts