473,748 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ajax -> javascript edit box display problems - please help

Bob
Hi,
Hope you can help me with this one. I'm at my wits end. I'm trying to
create an intelligent edit-box like the

excellent "Customer" one at the URL:

http://munich.schwarz-interactive.de/autocomplete.aspx

I have the back-end code (vb.net) successfully communicating with the
front page. It returns a string.

Problem is though - I'm having problems with the javascript. My
javascript is terrible. Not my forte I'm afraid. It's

the script called: "AutoComplete.j s". I downloaded it from the
following URL and imported it into my code:

http://www.codeplex.com/AjaxProStart...%2fStarterKit%

2fCSharp&change SetId=6175
***** BEGIN BACK-END CODE *****

<AjaxPro.AjaxNa mespace("WebFor m1")_
Public Class WebForm1
Inherits System.Web.UI.P age
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
AjaxPro.Utility .RegisterTypeFo rAjax(GetType(W ebForm1), Me.Page)
End Sub
<AjaxPro.AjaxMe thod()_
Public Function GetUsernameList (ByVal testParam As String) As String

'Get the request query
Dim strQuery As String = testParam

'Create the XML-like string to be sent back to the request
Dim strXmlNames As String = ""

'Dim arrStrNames As String() = {"Ian Suttle", "John Doe", "Alex
Wright", "Albert Einstein", "Sierra Tracy"}

Return arrStrNames

End Function
***** END BACK-END CODE *****

My Web.config looks like this:-

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.web>
<httpHandlers >
<add verb="POST,GET" path="ajaxpro/*.ashx"
type="AjaxPro.A jaxHandlerFacto ry, AjaxPro"/>
</httpHandlers>

</system.web>

</configuration>
The problem is though how do I make the string array communicate
successfully with the AutoComplete.js script. I finf

it very confusing. Any help/suggestions/comments/corrections much
appreciated.

Bob


***** BEGIN AutoComplete.js SCRIPT ******
addNamespace("M S.Web.AutoCompl ete");

MS.Web.AutoComp lete = Class.create();

Object.extend(M S.Web.AutoCompl ete.prototype, {
timer: null,
count: 10,
pos: -1,
waitAfterInput: 230,
minChars: 0,
children: null,

changeHighlight : function() {
var l = this.getLength( );
for(var i=0; i<this.count && i<l; i++) {
if(i == this.pos)
this.div.childN odes[i].className = "item selected";
else
this.div.childN odes[i].className = "item"
}
},
getItem: function(idx) {
return null;
},
getLength: function() {
return 0;
},
getDisplay: function(item) {
return item;
},
getValue: function(item) {
return item;
},
hide: function() {
this.div.style. display = "none";
},
show: function() {
this.changeHigh light();
this.div.style. display = "inline";
},
focusTextbox: function() {
this.ele.focus( );
},
select: function() {
if(this.pos -1) {
var v = this.getValue(t his.getItem(thi s.pos));
if(v != this.ele.value) {
this.ele.value = v;
if(this.childre n != null)
for(var i=0; i<this.children .length; i++) {
this.children[i].onparentchange (v);
}
}
}
this.hide();
},
onkeydown: function(e) {
var key = MS.Keys.getCode (e);
switch(key) {
case MS.Keys.TAB:
case MS.Keys.ENTER:
this.select();
if(key == MS.Keys.ENTER) MS.cancelEvent( e);
break;

case MS.Keys.ESC:
this.hide();
break;

case MS.Keys.KEYUP:
if(this.pos 0) this.pos--;
this.changeHigh light();
break;

case MS.Keys.KEYDOWN :
if(this.pos < this.getLength( ) -1 && this.pos <
this.count -1) this.pos++;
this.changeHigh light();
break;
}
},
onkeyup: function(e) {
switch(MS.Keys. getCode(e)) {
case MS.Keys.TAB:
case MS.Keys.ENTER:
case MS.Keys.ESC:
case MS.Keys.KEYUP:
case MS.Keys.KEYDOWN :
case MS.Keys.KEYLEFT :
case MS.Keys.KEYRIGH T:
case MS.Keys.ALT:
case MS.Keys.SHIFT:
case MS.Keys.CTRL:
break;

default:
if(this.ele.val ue.length < this.minChars)
return false;

if(this.timer != null) clearTimeout(th is.timer);
this.timer = setTimeout(this .getData.bind(t his),
this.waitAfterI nput);
break;
}
},
onfocus: function(e) {
this.changeHigh light();
},
onblur: function(e) {
setTimeout(this .hide.bind(this ), 200); // 200 msec for
onclick event of item
},
onmouseover: function(e) {
this.pos = MS.getTarget(e) .idx;
this.changeHigh light();
},
onclick: function(e) {
this.pos = MS.getTarget(e) .idx;
this.changeHigh light();
this.select();
},
ondblclick: function(e) {
if(this.ele.val ue == "")
this.getData();
},
onchange: function(e) {
if(this.childre n != null)
for(var i=0; i<this.children .length; i++) {
this.children[i].onparentchange (this.ele.value );
}
},
onparentchange: function(v) {
this.ele.value = "";
},
updateList: function() {
var l = this.getLength( );

for(var i=0; i<l && i<this.count; i++) {
// MS.setText(this .div.childNodes[i],
this.getDisplay (this.getItem(i )));
this.div.childN odes[i].innerHTML =
this.getDisplay (this.getItem(i ));

this.div.childN odes[i].style.display = "block";
}
if(this.pos l) this.pos = this.getLength( ) -1;

for(var i=l; i<this.count; i++) {
this.div.childN odes[i].style.display = "none";
}

if(this.pos l -1) {
this.pos = l -1;
}

if(this.div.chi ldNodes[0].clientHeight == 0) {
this.show();
this.updateList ();
return;
}

var h = (l < this.count ? l : this.count) *
this.div.childN odes[0].clientHeight;

if(h 0) {
this.div.style. height = h + "px";
this.show();
} else
this.hide();
},
getData: function() {
},
ondata: function() {
this.updateList ();
},
onresize: function() {
var r = MS.Position.get Bounds(this.ele );
this.ele.rect = r;
r.top += r.height;
MS.Position.set Location(this.d iv, r);
},
initialize: function(id, count, parent) {
this.ele = $(id);
if(this.ele == null || this.ele.tagNam e != "INPUT") throw
"Control could not be found.";
this.count = count != null && !isNaN(count) ? count :
this.count;

if(parent != null) { // no the parent control, instance of
MS.Web.AutoComp lete
parent.children = [];
parent.children .push(this);
}

addEvent(this.e le, "keydown", this.onkeydown. bind(this));
addEvent(this.e le, "keyup", this.onkeyup.bi nd(this));
addEvent(this.e le, "blur", this.onblur.bin d(this));
addEvent(this.e le, "focus", this.onfocus.bi nd(this));
addEvent(this.e le, "change", this.onchange.b ind(this));
addEvent(this.e le, "dblclick", this.ondblclick .bind(this));

// build list

this.div = document.create Element("div");
document.body.a ppendChild(this .div); // see iframe
ajaxpro

this.div.id = this.ele.id + "_list";

this.div.style. display = "none";
this.div.style. border = "1px solid black";

var r = MS.Position.get Bounds(this.ele );
this.ele.rect = r;
r.top += r.height;
MS.Position.set Bounds(this.div , r);

this.div.style. width = (r.width -2) + "px";

for(var i=0; i<this.count; i++) {
var d = document.create Element("div");
this.div.append Child(d);

// d.style.width = (r.width -2) + "px";
d.style.width = this.ele.client Width;
// d.style.height = r.height + "px";
d.style.whiteSp ace = "nowrap";
d.style.overflo w = "hidden";
d.className = this.ele.id + "_item";
d.idx = i;

addEvent(d, "mouseover" , this.onmouseove r.bind(this));
addEvent(d, "click", this.onclick.bi nd(this));

MS.setText(d, " ");
}

addEvent(window , "resize", this.onresize.b ind(this));

delete r;
}
}, false);
MS.Web.AutoComp leteDataTable = Class.create();
Object.extend(M S.Web.AutoCompl eteDataTable.pr ototype,
MS.Web.AutoComp lete.prototype, true);

Object.extend(M S.Web.AutoCompl eteDataTable.pr ototype, {
dt: null,

getItem: function(idx) {
if(idx >= 0 && idx < this.dt.Rows.le ngth)
return this.dt.Rows[idx];
return null;
},
getLength: function() {
if(this.dt != null && this.dt.Rows != null) {
return this.dt.Rows.le ngth;
}
return 0;
},
callback: function(res) {
if(res.error != null) {
// alert(res.error .Message);
return;
}
this.dt = res.value;
this.ondata();
}
}, true);

Mar 5 '07 #1
1 4952
On 5 mrt, 15:10, "Bob" <bwood...@mail. comwrote:
Hi,

Hope you can help me with this one. I'm at my wits end. I'm trying to
create an intelligent edit-box like the

excellent "Customer" one at the URL:

http://munich.schwarz-interactive.de/autocomplete.aspx

I have the back-end code (vb.net) successfully communicating with the
front page. It returns a string.

Problem is though - I'm having problems with the javascript. My
javascript is terrible. Not my forte I'm afraid. It's

the script called: "AutoComplete.j s". I downloaded it from the
following URL and imported it into my code:

http://www.codeplex.com/AjaxProStart.../DirectoryView...

2fCSharp&change SetId=6175

***** BEGIN BACK-END CODE *****

<AjaxPro.AjaxNa mespace("WebFor m1")_
Public Class WebForm1
Inherits System.Web.UI.P age

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
AjaxPro.Utility .RegisterTypeFo rAjax(GetType(W ebForm1), Me.Page)
End Sub

<AjaxPro.AjaxMe thod()_
Public Function GetUsernameList (ByVal testParam As String) As String

'Get the request query
Dim strQuery As String = testParam

'Create the XML-like string to be sent back to the request
Dim strXmlNames As String = ""

'Dim arrStrNames As String() = {"Ian Suttle", "John Doe", "Alex
Wright", "Albert Einstein", "Sierra Tracy"}

Return arrStrNames

End Function

***** END BACK-END CODE *****

My Web.config looks like this:-

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.web>
<httpHandlers >
<add verb="POST,GET" path="ajaxpro/*.ashx"
type="AjaxPro.A jaxHandlerFacto ry, AjaxPro"/>
</httpHandlers>

</system.web>

</configuration>

The problem is though how do I make the string array communicate
successfully with the AutoComplete.js script. I finf

it very confusing. Any help/suggestions/comments/corrections much
appreciated.

Bob

***** BEGIN AutoComplete.js SCRIPT ******

addNamespace("M S.Web.AutoCompl ete");

MS.Web.AutoComp lete = Class.create();

Object.extend(M S.Web.AutoCompl ete.prototype, {
timer: null,
count: 10,
pos: -1,
waitAfterInput: 230,
minChars: 0,
children: null,

changeHighlight : function() {
var l = this.getLength( );
for(var i=0; i<this.count && i<l; i++) {
if(i == this.pos)
this.div.childN odes[i].className = "item selected";
else
this.div.childN odes[i].className = "item"
}
},
getItem: function(idx) {
return null;
},
getLength: function() {
return 0;
},
getDisplay: function(item) {
return item;
},
getValue: function(item) {
return item;
},
hide: function() {
this.div.style. display = "none";
},
show: function() {
this.changeHigh light();
this.div.style. display = "inline";
},
focusTextbox: function() {
this.ele.focus( );
},
select: function() {
if(this.pos -1) {
var v = this.getValue(t his.getItem(thi s.pos));
if(v != this.ele.value) {
this.ele.value = v;
if(this.childre n != null)
for(var i=0; i<this.children .length; i++) {
this.children[i].onparentchange (v);
}
}
}
this.hide();
},
onkeydown: function(e) {
var key = MS.Keys.getCode (e);
switch(key) {
case MS.Keys.TAB:
case MS.Keys.ENTER:
this.select();
if(key == MS.Keys.ENTER) MS.cancelEvent( e);
break;

case MS.Keys.ESC:
this.hide();
break;

case MS.Keys.KEYUP:
if(this.pos 0) this.pos--;
this.changeHigh light();
break;

case MS.Keys.KEYDOWN :
if(this.pos < this.getLength( ) -1 && this.pos <
this.count -1) this.pos++;
this.changeHigh light();
break;
}
},
onkeyup: function(e) {
switch(MS.Keys. getCode(e)) {
case MS.Keys.TAB:
case MS.Keys.ENTER:
case MS.Keys.ESC:
case MS.Keys.KEYUP:
case MS.Keys.KEYDOWN :
case MS.Keys.KEYLEFT :
case MS.Keys.KEYRIGH T:
case MS.Keys.ALT:
case MS.Keys.SHIFT:
case MS.Keys.CTRL:
break;

default:
if(this.ele.val ue.length < this.minChars)
return false;

if(this.timer != null) clearTimeout(th is.timer);
this.timer = setTimeout(this .getData.bind(t his),
this.waitAfterI nput);
break;
}
},
onfocus: function(e) {
this.changeHigh light();
},
onblur: function(e) {
setTimeout(this .hide.bind(this ), 200); // 200 msec for
onclick event of item
},
onmouseover: function(e) {
this.pos = MS.getTarget(e) .idx;
this.changeHigh light();
},
onclick: function(e) {
this.pos = MS.getTarget(e) .idx;
this.changeHigh light();
this.select();
},
ondblclick: function(e) {
if(this.ele.val ue == "")
this.getData();
},
onchange: function(e) {
if(this.childre n != null)
for(var i=0; i<this.children .length; i++) {
this.children[i].onparentchange (this.ele.value );
}
},
onparentchange: function(v) {
this.ele.value = "";
},
updateList: function() {
var l = this.getLength( );

for(var i=0; i<l && i<this.count; i++) {
// MS.setText(this .div.childNodes[i],
this.getDisplay (this.getItem(i )));
this.div.childN odes[i].innerHTML =
this.getDisplay (this.getItem(i ));

this.div.childN odes[i].style.display = "block";
}
if(this.pos l) this.pos = this.getLength( ) -1;

for(var i=l; i<this.count; i++) {
this.div.childN odes[i].style.display = "none";
}

if(this.pos l -1) {
this.pos = l -1;
}

if(this.div.chi ldNodes[0].clientHeight == 0) {
this.show();
this.updateList ();
return;
}

var h = (l < this.count ? l : this.count) *
this.div.childN odes[0].clientHeight;

if(h 0) {
this.div.style. height = h + "px";
this.show();
} else
this.hide();
},
getData: function() {
},
ondata: function() {
this.updateList ();
},
onresize: function() {
var r = MS.Position.get Bounds(this.ele );
this.ele.rect = r;
r.top += r.height;
MS.Position.set Location(this.d iv, r);
},
initialize: function(id, count, parent) {
this.ele = $(id);
if(this.ele == null || this.ele.tagNam e != "INPUT") throw
"Control could not be found.";
this.count = count != null && !isNaN(count) ? count :
this.count;

if(parent != null) { // no the parent control, instance of
MS.Web.AutoComp lete
parent.children = [];
parent.children .push(this);
}

addEvent(this.e le, "keydown", this.onkeydown. bind(this));
addEvent(this.e le, "keyup", this.onkeyup.bi nd(this));
addEvent(this.e le, "blur", this.onblur.bin d(this));
addEvent(this.e le, "focus", this.onfocus.bi nd(this));
addEvent(this.e le, "change", this.onchange.b ind(this));
addEvent(this.e le, "dblclick", this.ondblclick .bind(this));

// build list

this.div = document.create Element("div");
document.body.a ppendChild(this .div); // see iframe
ajaxpro

this.div.id = this.ele.id + "_list";

this.div.style. display = "none";
this.div.style. border = "1px solid black";

var r = MS.Position.get Bounds(this.ele );
this.ele.rect = r;
r.top += r.height;
MS.Position.set Bounds(this.div , r);

this.div.style. width = (r.width -2) + "px";

for(var i=0; i<this.count; i++) {
var d = document.create Element("div");
this.div.append Child(d);

// d.style.width = (r.width -2) + "px";
d.style.width = this.ele.client Width;
// d.style.height = r.height + "px";
d.style.whiteSp ace = "nowrap";
d.style.overflo w = "hidden";
d.className = this.ele.id + "_item";
d.idx = i;

addEvent(d, "mouseover" , this.onmouseove r.bind(this));
addEvent(d, "click", this.onclick.bi nd(this));

MS.setText(d, " ");
}

addEvent(window , "resize", this.onresize.b ind(this));

delete r;
}

}, false);

MS.Web.AutoComp leteDataTable = Class.create();
Object.extend(M S.Web.AutoCompl eteDataTable.pr ototype,
MS.Web.AutoComp lete.prototype, true);

Object.extend(M S.Web.AutoCompl eteDataTable.pr ototype, {
dt: null,

getItem: function(idx) {
if(idx >= 0 && idx < this.dt.Rows.le ngth)
return this.dt.Rows[idx];
return null;
},
getLength: function() {
if(this.dt != null && this.dt.Rows != null) {
return this.dt.Rows.le ngth;
}
return 0;
},
callback: function(res) {
if(res.error != null) {
// alert(res.error .Message);
return;
}
this.dt = res.value;
this.ondata();
}

}, true);
Hi Bob,

Maybe I can help you by giving an alternative :
http://www.dhtmlgoodies.com/index.ht...x-dynamic-list

This scripts provides exactly the same functionality, and should be
quite easy to implement.
Kind regards,
Mathew

Mar 5 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
2099
by: Elizabeth | last post by:
Can you all give me your best recommendation(s) for books on AJAX ? Thanks ... - E -
8
2516
by: darrel | last post by:
I'm going to be diving into ASP.net 2.0 on a small project. I'd also like to use it as an excuse to start playing with some AJAX techniques. So, that leads to the obvious question: AJAX.net vs. Atlas? Anyone have any opinions on that? It looks like Atlas is still considered 'beta' so perhaps that's one strike against it.
7
1506
by: Thirsty Traveler | last post by:
Peter Bromberg has an interesting article eggheadcafe discussing AJAX libraries. He prefers ANTHEM.NET over AJAX.NET because it doesn't break the stateful page model. Our developers are currently using AJAX.NET after extensive research because ATLAS is currently not ready for prime-time and much more verbose than AJAX.NET. I was looking at some "Hello World" status on various libraies and ATLAS does, indeed, result in much more traffic....
5
1767
by: darrel | last post by:
I've been playing with prototype.js and scriptaculous to create some nice drag-and-drop interaction on my applications GUI. That's working well. Now I want to take the next step and start passing data back and forth between my page and the server via AJAX. In terms of .net, can someone give me the overall concept? Normally, I'd have a function in my codebehind that grabs a dataset and then binds that to a control on my aspx page.
5
2221
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only parts of your page. But in my application there are situation when I first notice on the server -- so AFTER sending an AJAX request -- that I have to update the complete page instead of only some parts. And what do I do now???
3
2317
by: bbawa1 | last post by:
I just want to know that I have already a web application. I want to use ajax in one of my web forms. I installed AJAX in my machine. Now to use ajax in my web application should I create a new web site in VS 2005 and select ASP.Net AJAX - Enabled Site and then copy my all the web forms and datasets from my existing web application to this new AJAX application to be able to use AJAX. I am wondering if there is any other way to use...
2
1894
by: Igor | last post by:
I just instaled AJAX framework. I can use it if I chose AJAX enabled aplication when I am creating new project. But I have some web aplication with no AJAX and I need to include it. It is not project, it is asp.net website. There is no .sln file or other visual studio project files. I started this web by chosing "New web site", not "New project". How can I include AJAX into this web? Thanks
6
1552
by: Jonathan Wood | last post by:
Greetings, I'd like to implement some AJAX features on an existing ASP.NET site. I have one example of doing this but, otherwise, don't know much about it. I have one question, though, about getting started: I notice that there are project templates for creating AJAX this and AJAX that. I'm a little confused about this. Am I not able to add AJAX features to an existing Web form? Why is it necessary to select an AJAX form or whatever?
2
1669
by: majidtou | last post by:
Hi , We have an HTML page which is using AJAX. We make an AJAX call which retrieves a table with mutiple rows. We need to extend this functionality. In the table, we want to put a button on each row. When this button is pressed, we want to update just the single row and keep the rest of the table the same. Currently the AJAX call looks something like this: document.getElementById("My_Div").innerHTML=xmlHttp.responseText; The server...
29
3319
by: zalek | last post by:
I am writing application with Ajax in sync mode - xmlHttp.open("GET", url, false). I noticed that in FireFox handler doesn't starts. It starts when I use xmlHttp.open("GET", url,true). I need to use it in sync mode. Any ideas what can I do? Thanks, Zalek.
0
8832
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,...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
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...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
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...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.