Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my code to display the list of customers.On clicking the particular customer it navigates to another page.


C#
function addTable() {

    var myTableDiv = document.getElementById("myDynamicTable");
    var table = document.createElement('TABLE');
    table.border='1';

    var tableBody = document.createElement('TBODY');
    table.appendChild(tableBody);
  db.transaction(function(transaction)
    {
    
     var pro=localStorage.getItem("ActiveProject");
     var activePro='Select Prjdb_id from ProjectTable where Proj_name="'+pro+'" ';
    transaction.executeSql(activePro , [],  function(transaction, result)
    {
             for (var i = 0; i <  result.rows.length; i++)
             {
                var row = result.rows.item(i);
                    id=row.Prjdb_id;
             }
               db=openDatabase(id, version, displayName,maxSize);
      if(id)
         {
          transaction.executeSql('SELECT * FROM customer' , [],  function(transaction, result)
          {
         
            le=result.rows.length;
            if (result.rows.length != 0)
            {
            var row = result.rows.item(i);
            var name= row.Cust_name;
            for(var i=0;i<2;i++)
            {
            var tr = document.createElement('TR');
            tableBody.appendChild(tr);
            for (var j=0; j<le; j++)
            {
            var td = document.createElement('TD');
            td.width='75';
            td.appendChild(document.createTextNode(name));
            tr.appendChild(td);
            }
            }
            $('#myDynamicTable').find('tr').click(function()
	      {
         rname = $(this).find('td:first').text();
								                                 db1.transaction(function(transaction) 
          { 
          transaction.executeSql('SELECT UserId FROM customer where Cust_name="'+rname+'" ', [],    function(transaction, result)
           {
	      	le=result.rows.length;
		for (var i = 0; i < result.rows.length; i++) 
                   { 
                var row = result.rows.item(i);	
		rid=row.UserId;
	          }
          });
         });
          document.location.href="datalist.html";	
        });		
            myTableDiv.appendChild(table);
            }
          },errorHandler);
         }
    });
 });



C#
function errorHandler(tx, error)
{
  alert("Database Error: " + error);
}



I need to get the name and id from this function to other function in another page ie,to the respective .js file of datalist.html.How can I get the values? Hope I am clear with the question..

plz help..
Posted

C#
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;
    console.log(vars);

}


var cid = getUrlVars()["rid"];
var rname =getUrlVars()["rname"];
 
Share this answer
 
Comments
Good. :) 5 Stars. :)
p@y@l 12-May-14 1:36am    
thank you :)
Welcome. :)
If you want to send anything from one page to another, use QueryString technique like...
JavaScript
document.location.href="datalist.html?rname=" + rname + "&rid=" + rid;

So, on the datalist.html page, you can retrieve these from the URL and do whatever you want.
 
Share this answer
 
Comments
Yeah, whatever function is executed on load of that page, inside that just retrieve these values and operate on them or I misunderstood your query?
p@y@l 9-May-14 8:18am    
No, u understood correctly.I needed this and the next step I got it,a javascript function.Thanks for you help!!! :)
Great. Glad to hear that.

Thanks,
Tadit

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