HighDots Forums  

Strange problem in JS code

Javascript JavaScript language (comp.lang.javascript)


Discuss Strange problem in JS code in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sniper
 
Posts: n/a

Default Strange problem in JS code - 10-05-2006 , 04:54 AM






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>
<xfutput 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


Reply With Quote
  #2  
Old   
Evertjan.
 
Posts: n/a

Default Re: Strange problem in JS code - 10-05-2006 , 05:01 AM






sniper wrote on 05 okt 2006 in comp.lang.javascript:

Quote:
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)


Reply With Quote
  #3  
Old   
sniper
 
Posts: n/a

Default Re: Strange problem in JS code - 10-05-2006 , 05:09 AM




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



Reply With Quote
  #4  
Old   
Evertjan.
 
Posts: n/a

Default Re: Strange problem in JS code - 10-05-2006 , 05:36 AM



sniper wrote on 05 okt 2006 in comp.lang.javascript:
Quote:
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)


Reply With Quote
  #5  
Old   
sniper
 
Posts: n/a

Default Re: Strange problem in JS code - 10-05-2006 , 05:50 AM




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



Reply With Quote
  #6  
Old   
Evertjan.
 
Posts: n/a

Default Re: Strange problem in JS code - 10-05-2006 , 05:54 AM



sniper wrote on 05 okt 2006 in comp.lang.javascript:
Quote:
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)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.