PDA

View Full Version : Problems controlling images


Zapcat
09-17-2002, 04:13 PM
Hi everyone!

I'm creating a site for selling car number plates, part of which will allow the user to enter the number plate letters & numbers they want and see a gif image of what it will look like.

I've put together some jscript to replace a transparent image with the character they type into a text box. So if they put in 'F' an image of the letter F appears on the plate. They can have up to 8 characters.

The problem is I keep getting the 'Object doesn't support this property or method' error message. Here's the jscript I'm using -

function addChars(evt, fld) {
var code = (window.Event) ? evt.which : evt.keyCode;
var char = String.fromCharCode(code);
if(char >= "0" && char <= "9"
|| char >= "A" && char <= "Z") {
document.getElementById("imgLet"+(fld.value.length)).src = String.toLowerCase(char) + ".gif";
}
return true;
}

The HTML code for the text box on the page is -

<input name="regPlate" size="14" maxlength="8" onKeyup="return addChars(event,this);">

Each image has a tag 'imgLet1', 'imgLet2' and so on up to 8.

Can anyone let me know where I'm going wrong?

adios
09-17-2002, 05:34 PM
Can't quite follow all that but, here's a fine example of 'Object doesn't support this property or method':

String.toLowerCase(char);

You invoke the String class method .toLowerCase() on an instance of a string itself (either a String object or, more likely, a string primitive). It's not a static function of the class, hence not invoked via the class (constructor) name, unlike String.fromCharCode(), e.g..

So...

char.toLowerCase();

And: don't use char as a variable name...it's reserved, being the single-character string type in Java, as a future extension presumably.

You're not in the slammer, are you? :eek:

Zapcat
09-17-2002, 05:39 PM
Thanks for your help Adios! I'll give it a try and get back if I need more help!

Mr J
09-17-2002, 07:52 PM
I too am a bit puzzled by the script but

char.toLowerCase()

is the correct way

to save using a reserved word you could go

oCHAR.toLowerCase()

if it is easier for referencing

Just a thought


;)

Zapcat
09-18-2002, 09:50 AM
It works!! Thanks for all your help. I think I was making my code overly complicated which was causing me the problems.

ZapCat:D