Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 61 votes, 3.46 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2003, 06:11 PM   PM User | #76
Choopernickel
Regular Coder

 
Join Date: Apr 2003
Location: Atlanta, GA
Posts: 487
Thanks: 0
Thanked 0 Times in 0 Posts
Choopernickel is an unknown quantity at this point
What line?
Choopernickel is offline   Reply With Quote
Old 12-16-2003, 10:45 AM   PM User | #77
Magic Man
New to the CF scene

 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Magic Man is an unknown quantity at this point
Sorry for the delay in getting back, thanks for the reply.

Running the example combobox.html on IE5 gives a jscript error,

Line: 12
Char: 3
Error: Object doesn't support this property or method
Code: 0
Magic Man is offline   Reply With Quote
Old 12-16-2003, 03:02 PM   PM User | #78
Choopernickel
Regular Coder

 
Join Date: Apr 2003
Location: Atlanta, GA
Posts: 487
Thanks: 0
Thanked 0 Times in 0 Posts
Choopernickel is an unknown quantity at this point
Paste this code into the file, above the definition of String.fromKeyCode :

Code:
if (typeof(String.fromCharCode) == 'undefined') {
    String.fromCharCode = function () {
        if (arguments.length = 0) {
            return "";
        }
        var charCodeChars = new Array(32);
            charCodeChars[9] = '\t';
            charCodeChars[13] = '\n';
            charCodeChars.push(' ','!','"','#','$','%','',"'",'(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@');
            charCodeChars.push('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\\',']','^','_','`');
            charCodeChars.push('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}','~');
    }
}
edit: damn forum software. Each line which begins charCodeChars.push( should continue as one line until you reach the ); there.

[meta]I know there's a way to get around the warping in 'java script:', but is there a way to get around that line-breakage?[/meta]

Last edited by Choopernickel; 12-16-2003 at 03:37 PM..
Choopernickel is offline   Reply With Quote
Old 12-16-2003, 04:12 PM   PM User | #79
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
Yes, you have to use trial-and-error escaping of characters in the string - when you find a particular combination removes a linebreak, it may well cause another somewhere else, but it will remove any linebreaks caused by exactly that combination that you're using. You could also insert some vB codes, they tend to help as well.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 12-16-2003, 04:48 PM   PM User | #80
Magic Man
New to the CF scene

 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Magic Man is an unknown quantity at this point
Still gives me the error in IE5.

I've got...


Code:
if (typeof(String.fromCharCode) == 'undefined') {
    String.fromCharCode = function () {
        if (arguments.length = 0) {
            return "";
        }
        var charCodeChars = new Array(32);
            charCodeChars[9] = '\t';
            charCodeChars[13] = '\n';
            charCodeChars.push(' ','!','"','#','$','%','',"'",'(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@');
            charCodeChars. push('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_','`');
            charCodeChars. push('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}','~');
    }
}

String.fromKeyCode = function(keyCode,evtType) {
	if (!evtType || !evtType.length)
		evtType = "keyDown";
	else if (evtType.toLowerCase() == "keypress")
		return String.fromCharCode(keyCode);
	var keyDownChars = new Array(16);
		keyDownChars[8] = '[Bksp]';
		keyDownChars[9] = '[Tab]';
		keyDownChars[12] = '[N5+shift]';
		keyDownChars[13] = '[Enter]';
		keyDownChars.push('[Shift]','[Ctrl]','[Alt]','[Pause]','[CapsLock]');
		for (i=11;i;--i) keyDownChars.push('undefined');
		keyDownChars[27] = '[Esc]';
		keyDownChars.push(' ','[PgUp]','[PgDn]','[End]','[Home]','[Left]','[Up]','[Right]','[Down]');
		for (i=7;i;--i) keyDownChars.push('undefined');
		keyDownChars[45] = '[Ins]';
		keyDownChars[46] = '[Del]';
		keyDownChars.push(['0',')'],['1','!'],['2','@'],['3','#'],['4','$'],['5','%'],['6','^'],['7','&'],['8','*'],['9','(']);
		for (i=7;i;--i) keyDownChars.push('undefined');
		keyDownChars.push('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[WinKey]');
		for (i=4;i;--i) keyDownChars.push('undefined');
		keyDownChars.push('0','1','2','3','4','5','6','7','8','9','*','+','undefined','-','.','/','[F1]','[F2]','[F3]','[F4]','[F5]','[F6]','[F7]','[F8]','[F9]','[F10]','[F11]','[F12]');
		for (i=62;i;--i) keyDownChars.push('undefined');
		keyDownChars[144] = '[NumLock]';
		keyDownChars[145] = '[ScrollLock]';
		keyDownChars.push([';',':'],['=','+'],[',','<'],['-','_'],['.','>'],['/','?'],['`','~']);
		for (i=26;i;--i) keyDownChars.push('undefined');
		keyDownChars.push(['[','{'],['\\','|'],[']','}'],["'",'"']);
	return keyDownChars[keyCode];
}


...but formatted without the line breaks

Gives the same error as before but offset by the new code, line 27 now I think.

Have I missed something...?

Thanks.
Magic Man is offline   Reply With Quote
Old 12-16-2003, 05:15 PM   PM User | #81
Choopernickel
Regular Coder

 
Join Date: Apr 2003
Location: Atlanta, GA
Posts: 487
Thanks: 0
Thanked 0 Times in 0 Posts
Choopernickel is an unknown quantity at this point
Whoops! I forgot to build the return string. Replace the new code with this:

Code:
if (typeof(String.fromCharCode) == 'undefined') {
    String.fromCharCode = function () {
        if (arguments.length = 0) {
            return "";
        }
        var charCodeChars = new Array(32),
            returnString = "",
            j;
        charCodeChars[9] = '\t';
        charCodeChars[13] = '\n';
        charCodeChars.push(' ','!','"','#','$','%','',"'",'(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@');
        charCodeChars.push('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\\',']','^','_','`');
        charCodeChars.push('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}','~');
        for (j=0;arguments.length>j;j++) {
            returnString += charCodeChars[arguments[j]];
        }
        return returnString;
    }
}
...and let me know where that gets you.

edit: have to double-escape the backslash in the post; don't forget to fix the line-breakage. also: don't use i for an array iterator when you're using italics vB tags later!

Last edited by Choopernickel; 12-16-2003 at 05:18 PM..
Choopernickel is offline   Reply With Quote
Old 12-16-2003, 07:21 PM   PM User | #82
Magic Man
New to the CF scene

 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Magic Man is an unknown quantity at this point
Thanks. I'll check it out when I'm in next.
Magic Man is offline   Reply With Quote
Old 12-17-2003, 01:07 AM   PM User | #83
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
I believe Array.push() is not supported in IE5. You have to prototype that method.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 12-17-2003, 01:57 PM   PM User | #84
Choopernickel
Regular Coder

 
Join Date: Apr 2003
Location: Atlanta, GA
Posts: 487
Thanks: 0
Thanked 0 Times in 0 Posts
Choopernickel is an unknown quantity at this point
That was indeed my next thought, glenn. I'll work on getting the whole deal integrated (including an Array.js file for any unsupported array methods), but until then, here's a copy with the push() method prototyped.
Attached Files
File Type: txt combobox.html.txt (44.4 KB, 6285 views)
Choopernickel is offline   Reply With Quote
Old 01-09-2004, 11:05 AM   PM User | #85
Magic Man
New to the CF scene

 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Magic Man is an unknown quantity at this point
Sorry for the delay in getting back.

All works well now in IE5. Excellent bit of coding there.


Cheers!
Magic Man is offline   Reply With Quote
Old 01-17-2005, 03:36 AM   PM User | #86
izzyb
New to the CF scene

 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
izzyb is an unknown quantity at this point
Question Has this code been tested in Firefox?

Great work Guys!

This script looks to be exactly what I need, but it doesn't seem to work exactly as described. Has it been tested under Firefox? The issues I'm running into are as follows:

1) No display of what is being typed in the status bar
2) Entering non-existing entries doesn't seem to work
3) Getting 'DOM2Event is not defined' errors, although it doesn't seem to be fatal.
4) Hitting backspace more times then the typed buffer causes the browser to go back to the previous page since backspace is a shortcut for back.


Are there work arounds for these issues?

...Izzy

---
Another thing... I have to agree with Glenngv re the timeout feature. At the very least, it seems way to quick. Having a way to turn this feature off or change the timeout value as Choopernickel suggested makes a lot of sense. Was any work done in this regard?

Last edited by izzyb; 01-17-2005 at 08:04 AM.. Reason: Another thing...
izzyb is offline   Reply With Quote
Old 01-18-2005, 06:35 AM   PM User | #87
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
I haven't look into too much details but here are my thoughts:

1) Firefox has a default setting to NOT allow script to change status bar text (in Tools > Option > Web Features > [Advanced...] > Advanced Javascript Options).

2) Haven't look into this.

3) Try changing this: (and other similar codes)
Code:
TypeAheadCombo.prototype.elementFocus = function (evt) {
  var theCombo;
  if (evt && window.addEventListener) {
    if (DOM2Event) {
      var e = new DOM2Event(evt, window.event, this);
    }
    theCombo = e.target.combo;
  }
...
}
to:
Code:
TypeAheadCombo.prototype.elementFocus = function (evt) {
  var theCombo;
  if (evt && window.addEventListener) {
    if (typeof DOM2Event != "undefined") {
      evt = new DOM2Event(evt, window.event, this);
    }
    theCombo = evt.target.combo;
  }
...
}
4) Haven't look into this.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app

Last edited by glenngv; 01-18-2005 at 08:20 AM..
glenngv is offline   Reply With Quote
Old 01-18-2005, 07:44 AM   PM User | #88
izzyb
New to the CF scene

 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
izzyb is an unknown quantity at this point
Thanks Glenn,

I haven't tried the code change yet, but it looks right. I have changed the option for allowing javascript to change the status bar, but it doesn't seem to have fixed the problem.

I tried looking into the timeout issue, but my javascript knowledge is limited and I'm still trying to figure out exactly what makes it tick. (sorry for the pun I tried simply increasing the timeout values from 1600 and 2400 to 36000, but it doesn't seem to make a difference. I'm thinking the bug is elsewhere. If I understand correctly, these timeouts are in milliseconds, so this should be 16 and 24 seconds respectfully, but I doubt I'm seeing more then 1 or 2 seconds before a timeout. It'd be nice to just disable the feature. I'll take another look at it tomorrow and see if I can figure out how to do that.

The more critical problem for my current needs is regaining the ability to add new entries. I have to say I've learned a lot about javascript by stuying this code. With any luck, I'll figure this one out yet tonight...

Thanks again for getting back to me so quickly and for your work on this script in the first place

...Izzy
izzyb is offline   Reply With Quote
Old 01-18-2005, 07:10 PM   PM User | #89
izzyb
New to the CF scene

 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
izzyb is an unknown quantity at this point
Code isn't running in Firefox

Looks like the code isn't running at all in firefox. The behaviour that I thought was the script looks to be built into firefox. It seems to do everything this script does, except the ability to add new entries, and the timeout seems really short.

That explains why my efforts to troubleshoot haven't responded as expected. I'm going to dig some more to see what the problem is.

...Izzy
izzyb is offline   Reply With Quote
Old 01-19-2005, 04:29 AM   PM User | #90
izzyb
New to the CF scene

 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
izzyb is an unknown quantity at this point
Thumbs up It's working now

I'm happy to say I finally have this script working.

Turned out to be a combination of problems, mostly in the perl script I was generating the page with. I wasn't calling the pageInit() script correctly and I neglected to give the form a name. The only real problems with this script were with the DOM2 calls. The solution Glenn suggested solves them.

I suggest the addition of something like this to help troubleshoot problems relating to forgetting to name your form.

Code:
        if (this.element.form.name.length == 0 ) {
                alert("The Form doesn't have a name.");
        }
I added it to the constructor below the following lines:

Code:
        // ASSOCIATION
        this.element = anElement;
My Javascript skills are limited, so there may be a better way to do this.

Thanks again for the help Glenn. And thanks guys for the great script!

...Izzy
izzyb is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

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

Forum Jump


All times are GMT +1. The time now is 01:24 AM.


Advertisement
Log in to turn off these ads.