Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Timothy Johnson
22,480 PointsAndroid Webview form
i'm building a checkbox form with a submit button using webview(html/javascript). Once the form is submitted i need the selected check box values to be printed out.
Is there anyway to do this other than with toast, because once the values are rendered i need a way to send it to the printer.
6 Answers
Ben Jakuben
Treehouse TeacherIf you are successfully doing it with a Toast, then that means you are accessing the values you need and can do anything you want with them. Paste in your code and we can look at it from there. :)
Timothy Johnson
22,480 Pointsi decided to just print the results out with some javascript.
Is there an way in javascript to hold values even after reloading a page, kind of like a cookie in php. What i am doing is creating a dinning service menu selector for a local hospital. Once the meal is selected i build a counter to count the number of times the menu is selected (Regular : 4 Soft : 2 Bland : 15 Low Sodium : 10,ect)
Ben Jakuben
Treehouse TeacherI haven't done this in a long time, so I don't remember (or have) the code I used, but it is possible. Here's a hack I found with a quick search that looks pretty useful: http://stackoverflow.com/a/3338656/475217
Timothy Johnson
22,480 Pointscool, I finally got every thing working. I email myself to apk file to test the app, and when it's submitted the results pops up on new page but it will not stay it pops in then disappear. How can i get it to stay?
function processOrder(){
//var x = document.forms[0].length;
//document.write(x)
var checkBoxes = document.getElementsByTagName('input');
//alert(checkBoxes.length);
var param = "<strong>Meal Plan:</strong>"+"<br>";
for (var counter=0; counter < checkBoxes.length; counter++) {
if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true) {
param += checkBoxes[counter].value + "<br>";
}
}
document.write(param);
}
Ben Jakuben
Treehouse TeacherBy new page, do you mean a new page in your WebView? I can't tell from this code; perhaps if you pasted in the rest of the code in your Activity file?
Timothy Johnson
22,480 Pointsyes , in the html. When I run the html from my editor it works fine until i try it on my android emulator.
<td>
<input type = 'checkbox' id = 'whole milk' name = 'Beverages and Juices' value = 'whole milk'>
<label for = 'whole milk'> whole milk </label>
</td>
<td>
<input type = 'checkbox' id = 'sweet tea' name = 'Beverages and Juices' value = 'sweet tea'>
<label for = 'sweet tea'> sweet tea, cold </label>
</td>
</tr>
<tr>
<td>
<input type = 'checkbox' id = 'small portions' name = 'Beverages and Juices' value = 'small portions'>
<label class = "smPortion"for = 'small portions'> Small Portions </label>
</td>
<td>
<input type = 'checkbox' id = 'cappuccino' name = 'Beverages and Juices' value = 'cappuccino'>
<label for = 'cappuccino'> Cappuccino </label>
</td>
</tr>
<tr class = "info">
<td colspan="2">
<p class = "smallText">apple, cranberry,orange,grape,pineapple, prune, tomato,v-8</p>
</td>
</tr>
<tr>
<td colspan="2" >
<input class = "btn btn-success" type = 'submit' value = 'submit order' id = "reg"onclick = 'processOrder()'>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</section>
<script src = "../js/script.js" type = "text/javascript"></script>
</body>
</html>
Ben Jakuben
Treehouse TeacherCan you paste in all your HTML code? It looks like your processOrder() function is just writing out the meal plan HTML, but I'm wondering where it is trying to write it. Perhaps it's not being written in a way that's valid for HTML?
Timothy Johnson
22,480 Pointsi figured it out, how do i add a print feature to the action bar?
Ben Jakuben
Treehouse TeacherFor the actual printing, have a look at Printing HTML Documents. As for adding the button in the Action Bar, check out one of these videos:
Timothy Johnson
22,480 Pointsok, thanks for taking the time to help out. you have been a great help