- This topic has 4 replies, 2 voices, and was last updated 12 years ago by support-octavio.
-
AuthorPosts
-
PygmyMemberHi, I’m used to coding C++ / C# and now I’d like to try my luck with MobiOne for phone-apps. Javascript is new to me, and I could use some help.
(I do realize my problem is probably more related to Javascript / JQuery than to MobiOne, but I’ve tried Googling and searching StackOverflow and I can’t figure this out.. which is why I’m asking here)
With the help of some examples I’m implementing a simple app for hobby purposes.
The screen I’m currently working on has a few combo-boxes with named items with corresponding floating point values.I want to handle the OnChanged event of these comboboxes, so that when any which one of them is changed, their selected values are multiplied and the output is shown in a non-editable text-box.
So I figured I’d try it like this :
Main Design name is named ‘PowerOutput’;
ComboBox 1 is named ‘CellVoltage’, Items are {{ “3.9v”, 3.9}, {“3.8v”, 3.8} …etc. }
ComboBox 2 is named ‘CellCount’, Items are {{ “2 cells”, 2}, {“3 cells”, 3} …etc. }
Text is named ‘TotalVoltage’function OnSomethingChanged() {
var cell_voltage = parseFloat($(‘#m1-PowerOutput-CellVoltage option:selected’).val());
var cell_count = parseFloat($(‘#m1-PowerOutput-CellCount option:selected’).val());
var total_voltage = cell_voltage * cell_count;
$(‘#m1-PowerOutput-TotalVoltage’).val(total_voltage);
}..and since you’re reading this post you’ll probably realize this doesn’t work.
(I’ve tried with and without the ‘option:selected’ part)How do I get the values of the selected items (so no the string name, but the actual value) from the comboboxes, and how do I display them multiplied in my textbox ?
PygmyMemberFor future reference (other beginners might encounter the same problems) I’ll answer my question myself, and pose a new one straight away 🙂
I found out it works like this :
function UpdateBatteryVoltage() {
var cell_voltage_value = $(‘select[name=”CellVoltage”]’).val();
var cell_voltage = parseFloat(cell_voltage_value);
var cell_count_value = $(‘select[name=”CellCount”]’).val();
var cell_count = parseFloat(cell_count_value);
var total_voltage = cell_voltage * cell_count;
$(‘#m1-PowerOutput-TotalVoltage’).val(total_voltage);
}*** IF *** TotalVoltage is a ‘TextField’. if it’s just ‘Text’ it doesn’t work.
My problem is that TextFields are editable, and since this is the result of a calculation I want it to be non-editable text.
Once again, feel free to point me in the right direction 🙂…to be continued.
PygmyMember….and another one :
Found out the Text field doesn’t update using .val(), but using .text(blah).
So this works :
function UpdateBatteryVoltage() {
var cell_voltage_value = $(‘select[name=”CellVoltage”]’).val();
var cell_voltage = parseFloat(cell_voltage_value);
var cell_count_value = $(‘select[name=”CellCount”]’).val();
var cell_count = parseFloat(cell_count_value);
var total_voltage = cell_voltage * cell_count;
$(‘#m1-PowerOutput-TotalVoltage’).text(total_voltage.toFixed(2).toString());
}
PygmyMemberWAITWAITWAIT HOLDUP !
Apparently my previous discoveries only work when I launch the specific ‘page’ called PowerOutput in the Test Center directly.
My PowerOutput page is actually a sub-page of my main app, and when I launch my main app and navigate to the PowerOutput sub-page it doesn’t work.
I’m thinking, this is most probably because my javescripting is bad and I should feel bad;
apparently all the statements I thought I fixed before (see previous posts) are now breaking my app.So :
var cell_voltage_value = $(‘select[name=”CellVoltage”]’).val();
probably doesn’t work in the full-version.I figure the right thing to do would be
var cell_voltage = parseFloat($(‘#m1-PowerOutput-CellVoltage’).val());but that just give’s me NaN’s (NotANumber’s).
So… I’m still stuck trying to get the appropriate value from a combobox…
support-octavioMemberHi Pygmy,
I suspect could be two reason for this issue:
1) The textfield that you are getting the value is empty.
2) A problem mixing code while you’re testing screens one by one:Note that when you generate files for an app, mobione generates a <App-name>_custom.js file. When you generate files for a secondary screen to test and add your code in <secondary-screen>_custom.js and after run <App-name> you’ll get the <App-name>_custom.js that doesn’t have the code that you added in <secondary-screen>_custom.js, your app couldn’t call the functions in the <secondary-screen>_custom.js
Hope this make sense.
-
AuthorPosts