List loosing style + can't get access to variable set in function
Hi guys.
I'm having two problems right now. I'm trying to write a page that takes out a number of items from a Web SQL and creates a list. Should be easy. The WQeb SQl is working fine (i can see the 4 rows in Chrome Web dev).
This is the javascript that I am adding at the end of the page (as done by a nettuts+ tutorial):
- <script>
- // Variables
- var html_sub_string;
- var html_string;
- $(document).ready(function () {
- showList();
-
- });
- function showList(){
- var db = openDatabase('LaurDB', '1.0', 'LaurDB', 2 * 1024 * 1024);
- db.transaction(function (tx) {
- tx.executeSql('SELECT * FROM laureates', [], function (tx, results) {
- var len = results.rows.length, i;
- for (i = 0; i < len; i++) {
- html_sub_string = html_sub_string + '<li>' + results.rows.item(i).category + ' ' + results.rows.item(i).year + '<br>' + results.rows.item(i).name + '</li>';
- }
- });
- });
-
- $('<li data-role="list-divider">Results</li>' + html_sub_string + ' <li data-role="list-divider">End Results</li>').appendTo('#listan');
- }
- </script>
However, I have 2 problems with this:
1/ I can't seem to get the vaule of html_sub_string out from the function that loops through the database. I thought that by defining it a Global variable it would be accessable from all functions? What am I doing wrong here?
2/ If I put this code at the bottom of the page the resulting list is halfway styled. It has rounded corners and has the "inset"-look but all colors are gone and the text is unstyled.
If I instead put the code in a separate js-file and references it before jquery.mobile-1.0a3.min.js it actually styles correctly.
<script src="jquery-1.5.min.js"></script>
<script src="result.js"></script>
<script src="jquery.mobile-1.0a3.min.js"></script>
While this list is being created on a separate page now I ultimately would like it to be created on the fly on the index-page through a onclick-even and when I tried it I got an unstyled list so that's why I still am wondering what is happening.
Thanks
/Björn