0

This is third time and i want to make it clear for my problem. So in the first page i display my whole record that i saved in database, and when i want to view the selected details at second page, i need to click the selected data and view, but nothing happen and i have no idea how to link the VIEW to second page that can show all the data, i had capture down the pictures so that hope you all can help me, big thanks.

This is First page

This is First page

This is the second page that i want to show the detail in the text field This is the second page that i want to show the detail in the text field

The coding is like this (first page::to show the whole records and link to second page)

    function showRecords(){
    results.innerHTML='';
    db.transaction(function(tx)
    {
        tx.executeSql(selectAll,[],function(tx,result)
        {
            dataset = result.rows;
            for(var i=0,item=null;i<dataset.length;i++)
            {
                item = dataset.item(i);
                results.innerHTML+=
                '<li>' + item['fname'] + ' <a href="#" onclick="loadRecord('+i+')">view</a>'+'<a href="#" onclick="deletetab('+item['id']+')">delete</a>'+'</li>';
            }
        });
    });
}

function loadRecord(i){
    var item=dataset.item(i);
    fname.value = item['fname'];
    id.value = item['id'];
    window.location.href="userup2.html?loadRecord("+i+")";
    return false;
}

Please give me some idea and example, im using web sql to store data, i already ask this question for few times and im newbie for the html and javascript, please help me and this is important.

newbie
  • 41
  • 11
  • AFAIK, you are attaching loadRecord(i) as queryString. So instead of function you can send the link id from first page and in second page you will get the id from url. So using id you can retrieve the values from database. – Kiran Jul 09 '12 at 03:36
  • hey @matrix, yes i think of it but i dont know how to code it as i got no idea, do you have any example to show the result? if the record is show in one page then i know how to retrieve, but i dont know how to retrieve from first page to second page – newbie Jul 09 '12 at 03:38

1 Answers1

1

Yes you can achieve it using query strings. As I am not aware of web-sql, I will show you how to add query string to url in first page and how to retrieve it in second page.

JS CODE:

function loadRecord(i){ 
    var item=dataset.item(i); 
    fname.value = item['fname']; 
    id.value = item['id']; 
    window.location.href="userup2.html?id="+i; 
    return false; 
} 

In the above function we are adding i (id of one record) as query string.

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

This code will help you to get the query string from url.

Example:

var id = getUrlVars()["id"];

The above line will help you to get id that you passed in first page and you may use it to retireve the details from database.

Hope this helps you :)

Kiran
  • 20,167
  • 11
  • 67
  • 99
  • is it all the code put in first page? anyway thanks matrix =) – newbie Jul 09 '12 at 03:51
  • first function loadRecord(i) you can put in first page that helps you to add query string and second function you can put in second page that helps you to get query string from url. – Kiran Jul 09 '12 at 03:52
  • Still got no result on that =(, can help me check? this is the first page :: http://jsfiddle.net/Gf9gp/ And this is second page:: http://jsfiddle.net/HH326/, the javascript of this two is same, so it is because of same code so it cant retrieve? – newbie Jul 09 '12 at 04:06
  • Where you are adding query string? Where you are retrieving? – Kiran Jul 09 '12 at 04:18
  • first page for adding query string and second page will display all the data while click view in first page, did you check my code? – newbie Jul 09 '12 at 05:19
  • the link of code already put, just a simple coding and i implemented your code too, but still no result – newbie Jul 09 '12 at 06:05
  • other things is i want render the data to second page and display in textfield – newbie Jul 09 '12 at 08:40
  • Did you got the output what you are expecting? – Kiran Jul 09 '12 at 08:42
  • hey man, i cant get the value for second page, it didnt display anything..do you check my code? – newbie Jul 09 '12 at 09:11
  • i think is because the getUrlVars, mayb it need specific to the related textfield only can show up? please check my code, i really have no idea T.T – newbie Jul 09 '12 at 09:46
  • Actually where is your code? I am not able to run fiddle. Its not working. – Kiran Jul 09 '12 at 10:45
  • fiddle let me save my code only, can save in your desktop then run the 2 html file... http://jsfiddle.net/Gf9gp/ <-- first page http://jsfiddle.net/HH326/ <-- second page – newbie Jul 10 '12 at 00:42
  • Do you have gmail? i think something missing coz it just can read the id but cant retrieve the data to other page and display on textfield – newbie Jul 10 '12 at 02:44
  • I am happy it helped. Welcome newbie :) – Kiran Jul 10 '12 at 09:12