By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,520 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,520 IT Pros & Developers. It's quick & easy.

Strange problem in JS code

P: n/a
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).singleNo deValue;
var element =
inst.evaluate('//instanceData/@selected',inst, null,
XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNo deValue;
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[i]);
}
}
]]>

</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:output 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

Oct 5 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 5 '06 #2

P: n/a

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

A result is not ready yet.
so ther's no solution ??

Oct 5 '06 #3

P: n/a
sniper wrote on 05 okt 2006 in comp.lang.javascript:
Evertjan. wrote:
>If things do not work when removing
an alert('')
in general it is a timing issue.

A result is not ready yet.
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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 5 '06 #4

P: n/a

Evertjan. wrote:
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.

Oct 5 '06 #5

P: n/a
sniper wrote on 05 okt 2006 in comp.lang.javascript:
Evertjan. wrote:
>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.
You are welcome.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 5 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.