- This topic has 14 replies, 5 voices, and was last updated 10 years, 9 months ago by support-octavio.
-
AuthorPosts
-
stealthtrooperMemberI want to create a page where the app user would complete a form with information and this information would then be stored in the form and be retrieved next time they excess the page. Also I’d like the facility for them to upload a photo either direct from the camera or from the photo gallery. The third feature I’d like is the form to complete a basic mathematical calculation based on one of their inputs. Please could someone give me a pointer how to achieve this?
BrandonMemberLocal storage should do what you want.
To set an item:
localStorage.setItem(‘name’,’my name’);
To get an item
localStorage.getItem(‘name’); //returns my name from the above setHere is an example of how to save a camera image into local storage:
http://cincyplanet.com/mobius/saving-camera-image-to-local-storage/
Code_AMemberTo perform the math calculation, select the “run JavaScript” option for the “on change” property for the text box(es). Then just add code to the JS window (or to the “<project_name>_custom.js” file) to do the math based on the user inputs.
Assume you have 3 text boxes and you want to add the values from 1 & 2 and display the result in 3:
var sum = parseFloat($('#m1-<project_name>-text1').val()) + parseFloat($('#m1-<project_name>-text2').val()); $('#m1-<project_name>-text3').val(sum);
stealthtrooperMemberThanks Guys, I’ll look at this ASAP and see how I get on:-)
stealthtrooperMemberI’ve managed to set up my form to gather information and keep it in local storage but I’m really struggling with the percentage calculation i need to do.
I’ve got an input id of “weight” being entered in Kg and want to automatically work out and display 5 and 6 percent of that figure to be displayed in grams but I just can’t figure out the code.
Any help would be be gratefully received 🙂
BrandonMemberTake your weight in kilograms at times that by 1000 to get grams:
x * 1000 = xgrams
times that by .05 to get 5-percentxgrams * .05 = 5-percent-xgrams
So, if your variable for the weight is myKG:
//I am doing them separately in case you need to access the different ones
myGrams = myKG*1000;
my5percent = myGrams*.05;//or .06 for 6 percentHope this helps.
stealthtrooperMemberThanks CincyPlanet
Sorry for the silly questions but its how to integrate those formulas into my html code that I’m stuck with. Also if I wanted to it to automatically calculate either 5 percent or 6 percent based on an age entry how would I achieve that please?
e.g. If age<12months calculate 5 percent of weight
If age>12months calculate 3 percent of weightThanks Again
Code_AMemberThere are two methods of applying JavaScript code to your app:
1) Click on any of your input widgets (eg text box, button, etc.) and set the On Change property to Run JavaScript. Then enter your code in to the JavaScript window.
2) Open the “<project_name>_custom.js” file in your project’s www folder and add JS code there. To call that code from your app just add the function call to the widget via method one above. For example, if you created a function called “myFunction()” in the the custom file then in the JS window for the widget you could call the function by entering “myFunction()”.
To answer your other question, yes you can just use if statements to change the multiplier based on the user input.
BrandonMemberHere you go. All the code is in the button properties.
Attachments:
You must be logged in to view attached files.
stealthtrooperMemberThank you guys – Ill have a go with this and see how I get on. Thank you again for the help:-)
stealthtrooperMemberI’ve got this code now which works fine in a normal internet browser but doesn’t seem to work in Mobi. Please can anyone help – this is driving me mad
<html>
<body>
To Calculate how much to feed please enter your animals weight below (in Kg) and click Submit
<form action=”javascript:calc()”>
<table width=”200″ border=”0″ align=”left” cellpadding=”0″ cellspacing=”0″>
<tr>
<td colspan=”5″> </td>
<td> </td>
</tr>
<tr>
<td>Weight:</td>
<td width=”168″><input type=”text” id=”input” size=”5″/></td>
<td width=”144″>Kg</td>
<td width=”30″> <div align=”center”></div></td>
<td width=”144″><input type=”Submit” /></td>
<td width=”109″> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#99FF66″>
<td colspan=”2″><strong>ADULT DOG </strong></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#99FF66″>
<td colspan=”5″>Quantity to feed per day: </td>
</tr>
<tr bgcolor=”#99FF66″>
<td><p></p>
Between</td>
<td><input type=”text” size=”5″ id=”output”/></td>
<td><div align=”center”>and</div></td>
<td><input type=”text” size=”5″ id=”output2″/></td>
<td><div align=”center”>grams </div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#99CCCC”>
<td><strong>PUPPY</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#99CCCC”>
<td colspan=”5″>Quantity to feed per day:</td>
</tr>
<tr bgcolor=”#99CCCC”>
<td><p></p>
Between</td>
<td><input type=”text” size=”5″ id=”output3″/></td>
<td><div align=”center”>and</div></td>
<td><input type=”text” size=”5″ id=”output4″/></td>
<td><div align=”center”>grams </div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#CC99FF”>
<td><strong>CAT</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#CC99FF”>
<td colspan=”5″>Quantity to feed per day: </td>
</tr>
<tr bgcolor=”#CC99FF”>
<td> Between </td>
<td><input type=”text” size=”5″ id=”output5″/></td>
<td><div align=”center”>and</div></td>
<td><input type=”text” size=”5″ id=”output6″/></td>
<td><div align=”center”>grams </div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr><td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<br />
<p> <br />
</p>
<p> <br />
</p>
<p></p>
</form>
</body>
<script>
function calc() {
var i = document.getElementById(“input”).value;
var m = (i*1000/100) * 2;
var o = (i*1000/100) * 3;
var p = (i*1000/100) * 5;
var q = (i*1000/100) * 6;
var r = (i*1000/100) * 2;
var s = (i*1000/100) * 3;
document.getElementById(“output”).value = m;
document.getElementById(“output2”).value = o;
document.getElementById(“output3”).value = p;
document.getElementById(“output4”).value = q;
document.getElementById(“output5”).value = r;
document.getElementById(“output6”).value = s;
}
</script>
</html>Attachments:
You must be logged in to view attached files.
support-michaelKeymasterYou copy/pasted a full html doc src into the html widget (i.e., <head></head><body>visible stuff here</body>). This widget merges whatever html you provide into the current document. Thus your code completely breaks the DOM. If you are going to copy/paste code it should only be the html content between <body>visible stuff</body> tags, i.e., exclude the <body> tags.
BrandonMemberIf it were me I would take the time to convert it to a mobione form using the widget controls over the html code. I believe this give you greater control over the design and interaction in mobione studio.
stealthtrooperMemberHi Michael,
I think this is what you mean by removing the tags etc. but it still doesn’t work:-(
<div style = “formholder” width=”200″>
To Calculate how much feed please enter your animals weight below (in Kg) and click Submit
<form action=”javascript:calc()”>
<table width=”150″ border=”0″ align=”left” cellpadding=”0″ cellspacing=”0″>
<tr>
<td width=”57″>Weight:</td>
<td width=”30″><div align=”center”>
<input type=”text” id=”input” size=”5″/>
</div></td>
<td width=”35″>Kg</td>
<td width=”30″><div align=”center”></div></td>
<td width=”56″><input type=”Submit” /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#99FF66″>
<td colspan=”2″><strong>ADULT DOG </strong></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#99FF66″>
<td colspan=”5″>Quantity to feed per day: </td>
</tr>
<tr bgcolor=”#99FF66″>
<td><p></p>
Between</td>
<td><div align=”center”>
<input type=”text” size=”5″ id=”output”/>
</div></td>
<td><div align=”center”>and</div></td>
<td><input type=”text” size=”5″ id=”output2″/></td>
<td><div align=”center”>grams </div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#99CCCC”>
<td><strong>PUPPY</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#99CCCC”>
<td colspan=”5″>Quantity to feed per day:</td>
</tr>
<tr bgcolor=”#99CCCC”>
<td><p></p>
Between</td>
<td><div align=”center”>
<input type=”text” size=”5″ id=”output3″/>
</div></td>
<td><div align=”center”>and</div></td>
<td><input type=”text” size=”5″ id=”output4″/></td>
<td><div align=”center”>grams </div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#CC99FF”>
<td><strong>CAT</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr bgcolor=”#CC99FF”>
<td colspan=”5″>Quantity to feed per day: </td>
</tr>
<tr bgcolor=”#CC99FF”>
<td> Between </td>
<td><div align=”center”>
<input type=”text” size=”5″ id=”output5″/>
</div></td>
<td><div align=”center”>and</div></td>
<td><input type=”text” size=”5″ id=”output6″/></td>
<td><div align=”center”>grams </div></td>
</tr>
</table>
<br />
<p> <br />
</p>
<p> <br />
</p>
<p></p>
</form>
</div>
<script>
function calc() {
var i = document.getElementById(“input”).value;
var m = (i*10) * 2;
var o = (i*1000/100) * 3;
var p = (i*1000/100) * 5;
var q = (i*1000/100) * 6;
var r = (i*1000/100) * 2;
var s = (i*1000/100) * 3;
document.getElementById(“output”).value = m;
document.getElementById(“output2”).value = o;
document.getElementById(“output3”).value = p;
document.getElementById(“output4”).value = q;
document.getElementById(“output5”).value = r;
document.getElementById(“output6”).value = s;
}
</script>
support-octavioMemberHi stealthtrooper,
I have consulted the dev team and learn that your form is not being submitted because phoneui catches “submit” event and calls e.preventDefault. A workaround is adding an onclick handler in your button that calls the function:
<input type="Submit" onclick="javascript:calc()" />
-
AuthorPosts