Hej Everybody
I have tried do make an "instant search" in javascript, ie everytime one
hits a key the javascript sends the request to a database and returns
the result into a table.
The problem is occuring when the result i given. When one do a search
the given result is appended to the existing rowx in the table instead
of redrawing the table.
Example:
Element1
Element2
Element3
Element4
Element5
Search = 5
new result:
Element1
Element2
Element3
Element4
Element5
Element5
The wanted result is:
Element5
How do I make this happen?
JAVASCRIPT FUNCTIONS:
//This function is called everytime a key i press down in the input field
function search(){
var search = document.getEle mentById("searc h").value;
process(search) ;
}
// call server asynchronously
function process(in_valu e)
{
var server = "phoneXML.php?s earch="+in_valu e;
// only continue if xmlHttp isn't void
if (xmlHttp)
{
// try to connect to the server
try
{
// remove this line if you don't like the 'Receiving...' message
display("Receiv ing new message from server...")
// make asynchronous HTTP request to retrieve new message
xmlHttp.open("G ET", server, true);
xmlHttp.onready statechange = handleRequestSt ateChange;
xmlHttp.send(nu ll);
}
catch(e)
{
displayError(e. toString());
}
}
}
//Parsing the xml file and puts the final result in "finalArray "
function handleServerRes ponse()
{
var contactArray = null;
var idArray = null;
var emailArray = null;
var phoneArray = null;
var firmaArray = null;
finalArray = Array();
// read the message from the server
var xmlResponse = xmlHttp.respons eXML;
// catching potential errors with IE and Opera
if (!xmlResponse || !xmlResponse.do cumentElement)
throw("Invalid XML structure:\n" + xmlHttp.respons eText);
// catching potential errors with Firefox
var rootNodeName = xmlResponse.doc umentElement.no deName;
if (rootNodeName == "parsererro r") throw("Invalid XML structure");
// obtain the XML's document element
xmlRoot = xmlResponse.doc umentElement;
contactArray = xmlRoot.getElem entsByTagName(" strContact");
idArray = xmlRoot.getElem entsByTagName(" idIntraContact" );
emailArray = xmlRoot.getElem entsByTagName(" strEmail");
phoneArray = xmlRoot.getElem entsByTagName(" strPhone");
firmaArray = xmlRoot.getElem entsByTagName(" strFirma");
// generate HTML output
// iterate through the arrays and create an HTML structure
for (var i=0; i<idArray.lengt h; i++){
finalArray[idArray.item(i) .firstChild.dat a] = new Array();
finalArray[idArray.item(i) .firstChild.dat a]["strContact "] =
contactArray.it em(i).firstChil d.data;
//Er der noget i den??
if(xmlRoot.getE lementsByTagNam e("strEmail")[i].firstChild)
finalArray[idArray.item(i) .firstChild.dat a]["strEmail"] =
emailArray.item (i).firstChild. data;
else
finalArray[idArray.item(i) .firstChild.dat a]["strEmail"] = "";
//Er der noget i den??
if(xmlRoot.getE lementsByTagNam e("strPhone")[i].firstChild)
finalArray[idArray.item(i) .firstChild.dat a]["strPhone"] =
phoneArray.item (i).firstChild. data;
else
finalArray[idArray.item(i) .firstChild.dat a]["strPhone"] = "";
finalArray[idArray.item(i) .firstChild.dat a]["strFirma"] =
firmaArray.item (i).firstChild. data;
}
display();//This is the one who draws
}
function display()
{
//Find the table we want to append to
var selector =
document.getEle mentById("selec tor").getElemen tsByTagName("tb ody")[0];
for(var i in finalArray){//Run through "finalArray "
var strPhone = finalArray[i]["strPhone"]
row = document.create Element("tr");//New row
cell1 = document.create Element("td");//New cell
cell1.setAttrib ute("id", "product");//Cell attributes
cell1.innerHTML = finalArray[i]["strFirma"];//Cell data
cell2 = document.create Element("td");
cell2.setAttrib ute("id", "product");
cell2.innerHTML = "<a id='cats'
href='contacts. php?action=show &id="+ i +"'>"+
finalArray[i]["strContact "] +"</a>";
cell3 = document.create Element("td");
cell3.setAttrib ute("id", "product");
cell3.innerHTML = strPhone;
cell4 = document.create Element("td");
cell4.setAttrib ute("id", "product");
cell4.innerHTML = finalArray[i]["strEmail"];
row.appendChild (cell1);
row.appendChild (cell2);
row.appendChild (cell3);
row.appendChild (cell4);
selector.append Child(row);//Add the new row to the existing table
}
} 2 2854
Memborg wrote:
Hej Everybody
I have tried do make an "instant search" in javascript, ie everytime one
hits a key the javascript sends the request to a database and returns
the result into a table.
The problem is occuring when the result i given. When one do a search
the given result is appended to the existing rowx in the table instead
of redrawing the table.
Isn't appending exactly what your display() method sets out to do?
Nowhere does it remove any table content. Find the row(s) you want to
remove and call removeChild on their parent node.
[snip]
>
function display()
{
//Find the table we want to append to
var selector =
document.getEle mentById("selec tor").getElemen tsByTagName("tb ody")[0];
for(var i in finalArray){//Run through "finalArray "
var strPhone = finalArray[i]["strPhone"]
row = document.create Element("tr");//New row
Why don't you use inserRow() (ditto for cells)?
--
Ian Collins.
Ian Collins skrev:
Memborg wrote:
>Hej Everybody
I have tried do make an "instant search" in javascript, ie everytime one hits a key the javascript sends the request to a database and returns the result into a table.
The problem is occuring when the result i given. When one do a search the given result is appended to the existing rowx in the table instead of redrawing the table.
Isn't appending exactly what your display() method sets out to do?
Nowhere does it remove any table content. Find the row(s) you want to
remove and call removeChild on their parent node.
[snip]
>function display() { //Find the table we want to append to var selector = document.getEl ementById("sele ctor").getEleme ntsByTagName("t body")[0];
for(var i in finalArray){//Run through "finalArray "
var strPhone = finalArray[i]["strPhone"]
row = document.create Element("tr");//New row
Why don't you use inserRow() (ditto for cells)?
After some research I found that there is a deleteRow() function and i
work for me.
I have no idea why I don't use insertRow(). I wasn't aware of the
function i guess. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Scott |
last post by:
I have a clickable graph that resides on page 1. If user clicks a data point
on the graph, the page runs again yeilding a 2nd graph that shows a more
detailed graph.
Problem is, I have a recordset table on the 2nd graph page and because the
user gets to it by clicking the graph, the page doesn't properly post to
render the recordset table. I can click "Refresh" on 2nd page and table
displays fine.
Is there an ASP refresh command that...
|
by: Danny |
last post by:
HI
How can I refresh the main project window in code in ms access 2000
For example, I create a new table, but when I minimize the form, the table
is not there until I do F5 (refresh).
I do the db.TableDefs.Refresh, but I guess this is not applied to the
project window for tables
thanks
|
by: Jeronimo Bertran |
last post by:
Hi,
I have a page with a very data intensive grid which needs to be
automatically refreshed constantly if a change is detected. In order to
not refresh the complete page so often, I created an iframe on my page
whose html has the refresh meta as follows :
<meta http-equiv="refresh" content="10">
The iframe is effectivelyh refreshed every 10 seconds without having the
|
by: Jim Little |
last post by:
Hello,
I'm driving myself crazy either because I'm missing something about ASP.NET,
or what I'm trying to do simply can't be done.
First, I am not using session variables to track state. My app will
ultimately be web-farmed, so I resisted using either session variables.
Second, what I'm trying to do is easy. What I'm trying to prevent seems
impossible.
|
by: gg77 |
last post by:
Hi,
I don't have much knowledge of the table control. I am basically trying to
use a table thats populated with data rows from a dataSet but currently
things aren't working for me.
below is the sample HTML that I have:
<asp:TableRow>
<asp:TableCell Text="Company" ID="CompanyCode"
| |
by: Juan Romero |
last post by:
Hey guys, please HELP
I am going nuts with the datagrid control.
I cannot get the damn control to refresh. I am using soap to get information
from a web service. I have an XML writer output the file to a folder, and
then I read it back into the dataset using the dataset1.readxml. Up to this
point, everything works wonderfully. The query executes, the dataset gets
populated, and I get the results displayed in the datagrid.
|
by: Simon Strandgaard |
last post by:
Hi group,
my setup:
I have a GridView that extracts data from my table (a SqlDataSource).
For each row, I have an 'edit' button and a 'delete' button.
The 'edit' button opens a popup, through which one can insert and edit
the table.
The 'delete' button deletes the row.
|
by: Lisa |
last post by:
I have an Access 2000 application that uses the following function to
re-link my tables when I switch from my Current back end to a Dummy
back end. I also use it to refresh my links.
Function CreateODBCLinkedTables() As Boolean
On Error GoTo CreateODBCLinkedTables_Err
Dim strTblName As String, strConn As String
Dim db As DataBase, rs As Recordset, tbl As TableDef
Dim DatabaseName As String
Dim ServerName As String
|
by: chetu |
last post by:
I have two pivot tables, but when my macro refreshes the pivot tables it refreshes all, but I want it to pick say for example;
Say range "B8" of pivot table 1 is 60, I want the range "x2" of pivot table 7 also to pick 60 and then refersh it. Below is the coding which I have done, can anyone help?
Range("B8").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Range("B31").Select
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |