Strange problem in JS code

S

sniper

hi all;
i'm doing here an autocompletion module in the envirnment
(XFORMS/XHTML).
this is the code:

<?xml version="1.0" encoding="UTF-8"?>
<xhtml:html xmlns="http://xforms.websynapsis.com"
xmlns:books="http://books.websynapsis.com"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xhtml:head>

<xf:model id="myModel">
<xf:instance xmlns="" id="myInstance">
<instanceData selected="">
<itemlist>
</itemlist>
</instanceData>
</xf:instance>

<xf:bind model="myModel"
nodeset="instance('myInstance')/itemlist/item[position()&lt;6]"
id="__items" />
</xf:model>

<xhtml:script type="text/javascript">
<![CDATA[
function affiche1()
{
var model = document.getElementById("myModel");
var instanceDoc = model.getInstanceDocument("myInstance");
var sel = document.getElementById("__itemList");
sel.addEventListener("keyup",g,true);
}
function g()
{
alert("ouf")
changeModel1(1)
}

function changeModel1(count1)
{
vider()
var found=new Array()
var model = document.getElementById("myModel");
if(model != null)
{
var inst = model.getInstanceDocument("myInstance");
if(inst != null)
{
var insertPoint = inst.getElementsByTagName("itemlist").item(0);
var itemCount = insertPoint.getElementsByTagName("item").length;
var k=0;
if(k<count1)
{
var element1 = inst.evaluate('//instanceData',inst,
null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
var element =
inst.evaluate('//instanceData/@selected',inst, null,
XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;


found=search(element.textContent)
vider()
for(x=0;x<found.length;x++)
{
var item = document.createElementNS("", "item");
item.appendChild(document.createTextNode(found[x]));
insertPoint.appendChild(item);
k=k+1;
}
} }

rafraichir(model,element)

}
}


function search(value)
{
//alert("entrée")
var tab=remplir()
var y=0
var tab2=new Array()
for(x=0;x<tab.length;x++)
{
if(value.length>0 && tab[x].indexOf(value)>-1 )
{
tab2[y]=tab[x]
y=y+1
}
}
return(tab2)
}
function rafraichir(model,element)
{
model.rebuild();
model.refresh();

}

function remplir()
{
var tab=new Array()
tab[0]="bbcd"
tab[1]="abbc"
tab[2]="bb"
tab[3]="a"
return tab

}
function vider()
{
var model = document.getElementById("myModel");
var inst = model.getInstanceDocument("myInstance");
var insertPoint = inst.getElementsByTagName("itemlist").item(0);
var items = insertPoint.getElementsByTagName("item");
for( i=0; i<items.length; i++)
{
insertPoint.removeChild(items);
}
}
]]>

</xhtml:script>


<xhtml:style type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
xf|select1 div { width: 100px; }

</xhtml:style>


</xhtml:head>

<xhtml:body>

<xhtml:table border="0" cellspacing="0" cellpadding="0">
<xhtml:tr>
<xhtml:td valign="top">
<xf:select1 id="__itemList" ref="@selected" selection="open"
appearance="minimal">
<xf:itemset model="myModel"
nodeset="instance('myInstance')/itemlist/item" id="__items">
<xf:label ref="." />
<xf:value ref="." />
</xf:itemset>
</xf:select1>
<xhtml:span style="font-weight:bold">Selected item: </xhtml:span>
<xf:eek:utput model="myModel" ref="@selected" />

</xhtml:td>
<xhtml:td width="20px">
</xhtml:td>
</xhtml:tr>
</xhtml:table>
<xhtml:br />
<xhtml:input type="button" value="Add Listener" onclick="affiche1();"/>
</xhtml:body>
</xhtml:html>


the strange thing is that if i remove the alert("ouf") nothing work.
can you help me to find the pb.
Thanks
 
E

Evertjan.

sniper wrote on 05 okt 2006 in comp.lang.javascript:
the strange thing is that if i remove the alert("ouf") nothing work.
can you help me to find the pb.

[pb's are not part of the usenet vocabulary]

If things do not work when removing
an alert('')
in general it is a timing issue.

A result is not ready yet.
 
E

Evertjan.

sniper wrote on 05 okt 2006 in comp.lang.javascript:
so ther's no solution ??

Did I say that?

Usenet is not a payed helpdesk,
I was suggesting where to look for the bug.

Perhaps, if you do not follow my lead,
someone else is kind enough to plough through your long code.
 
S

sniper

Evertjan. said:
Usenet is not a payed helpdesk,
I was suggesting where to look for the bug.

Perhaps, if you do not follow my lead,
someone else is kind enough to plough through your long code.

thanks for your precious help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top