Click here to Skip to main content
16,016,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im working on a mobile web app using jQTouch for the theme. Im having an issue trying to pass a hyperlink parameter/value to a javascript function. The link is part of a list that is generated from a websql query:

THIS IS THE LIST - which nicely display with only the ID of a row set to "xres" as an id on a div tag in the main HTML
function dspList() {
db.transaction(function (tx) {
  tx.executeSql('SELECT * FROM UBP', [], function (tx, results) {
   var len = results.rows.length, i;
   for (i = 0; i < len; i++){
     xres = "<li class='arrow'><a href='#userdisplay'  önclick='dspUser()'>" + results.rows.item(i).uaid + "</a></li>";
     document.querySelector('#xres').innerHTML +=  xres;
   }
 }, null);
});
}


THIS IS THE HTML TAG THAT DISPLAYS THE LIST:
<div id="myinfo">
    <div class="toolbar">
        <h1>My Info</h1>
        <a class="button back" href="#home"  önclick="goRefresh(0)">Back</a>
    </div>
    <ul class="edgetoedge">
    <div id="xres"></div>
    </ul>
</div>


When clicking one of the items on the list, ie:
3459
4436
2255

..it runs this javascript function:
function dspUser() {
var xuaid = document.getElementById("xres");
db.transaction(function (tx) {
  tx.executeSql('SELECT * FROM UBP WHERE (uaid = ?) ', [xuaid], function (tx, results) {
     {
     xres1 = results.rows.item(0).uaid + " - " + results.rows.item(0).user;
     document.querySelector('#xres1').innerHTML +=  xres1;
     }
 }, null);
});
}


..and displays with this HTML:
<div id="userdisplay">

    <div class="toolbar">
        <h1>User Information</h1>
        <a class="button back" href="#myinfo">Back</a>
    </div>

    <div>
        <ul class="plain12">
        <span class="fontleft18"><div id="xres1">Results here..</div></span>
        </ul>
    </div>

</div>


Im very new at javascript, but would really like to learn and build some web apps. Can anyone help me figure out why I cant pass the value of the id=xres to the function dspUser() so that I can query the websql for just that particular id/row? Am I using the correct function with the document.getElementById? Is this even the correct way/process to query the websql from a list display that was also generated by a websql query?

Any help would be greatly appreciated.

Octavious
Posted

1 solution

Hi--

i think you have to create a loop because your query returns more than one data.
the function getElementById is correct however it will just return only the element collection which in your case is all the element of the
tag.

for you to get the value of each elements inside the tag:

JavaScript
var xuaid = document.getElementById("xres");

for var x = 0; x < myObj.length; x++){

     alert (xuaid.childNodes[x].value);

}


..something like that.. and here's a useful link:

dottoro
 
Share this answer
 
Comments
octavious27 22-May-12 13:55pm    
Thanks for the reply. I'll try this out - although it does not make full sense to me right now as loop is within the function that is suppose to display the single item selected from the list. How does it obtain the correct item? I also checked out the link included to dottoro and it gave just a bit more help. Will continue to work on this and see what I get.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900