Update: abdu's answer worked, but only if I embedded the script in my index.html file (rather than including it in a linked app.js file like I had)...
I'm creating some simple mobile apps in jquery mobile and angularjs (not together), to see which I want to build on...
I'm having a problem in jquery mobile. When you submit the form, instead of simply dynamically updating the list, it refreshes and clears the page:
<div id="home" data-role="page">
<div data-role="content">
<form id="form1">
<input id="list-text" type="text" placeholder="enter text here...">
<button id="button1" onclick="addToList()" >Add</button>
</form>
<ul id="the-list" data-role="listview"></ul>
</div>
function addToList() {
var newText = $('#list-text').val();
$('#the-list').append('<li>' + newText + '</li>');
// will be updating localStorage here
$('#list-text').val(' ');
}
I've tried researching this and still don't understand why.... Maybe I need more understanding of forms and jquery.