Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 26th, 2004, 04:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default undefined

What does it mean when there is a javascript error such as:

Erro: 't1' is undefined?

I'm trying to use roll over function whereby you rollover an image and it appears somewhere else and I'm getting this error:

this is my code:


    if (document.images) {
        Thumb1 = new Image
        Thumb2 = new Image
        Thumb3 = new Image
        Thumb4 = new Image
        Thumb5 = new Image
        Thumb6 = new Image

        t1.src = "image_bin/thumbs/<%=strT1%>"
        t2.src = "image_bin/thumbs/<%=strT2%>"
        t3.src = "image_bin/thumbs/<%=strT3%>"
        t4.src = "image_bin/thumbs/<%=strT4%>"
        t5.src = "image_bin/thumbs/<%=strT5%>"
        t6.src = "image_bin/thumbs/<%=strT6%>"

        }

    else {

    t1 = ""
    t2 = ""
    t3 = ""
    t4 = ""
    t5 = ""
    t6 = ""
    document.main = ""

    }

    function chgImg(imgField,newImg) {
        if (document.images) {
            document[imgField].src= eval(newImg + ".src")
        }
    }


and this is where the error occurs:

<td width="16%" onmouseover="chgImg('main','t1')">

any help greatly appreciated.

Thanks

Adam

  #2 (permalink)  
Old November 26th, 2004, 04:48 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It normally means you are using an undeclared variable. You try to assign a string to t1.src but you haven't declared t1, either locally as
Code:
var t1
or globally as
Code:
ti = ""
--

Joe (Microsoft MVP - XML)
  #3 (permalink)  
Old November 26th, 2004, 04:51 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Adam,

The error often occurs when you try and access a method or property of an object that hasn't been created

I think the lines
Code:
Thumb1 = new Image
Thumb2 = new Image 
...
need to be
Code:
t1 = new Image 
t2 = new Image
as you haven't created t1 etc as images before setting their src properties

in addition, the method call
Code:
chgImg('main','t1')
needs to be
Code:
chgImg('main',t1)
otherwise you are passing a string value of 't1' rather than the image object you created earlier in the page & the code tries to access it's src property causing an error

HTH,

Chris

  #4 (permalink)  
Old November 28th, 2004, 06:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

great - thanks guys I'll give it a bash.

  #5 (permalink)  
Old September 24th, 2007, 09:51 AM
Registered User
 
Join Date: Sep 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Greetings,

I'm new to this forum and I found this string through
a web search.

I have a similar issue except that I only get the error
the first time that I land on a page.

Here is some sample js code:

function preload(){

    if(document.images)
        {
tts_0 = new Image();
tts_0.src = "../image/site_rbttn_tts.gif";
tts_1 = new Image();
tts_1.src = "../image/site_rbttn_tts_ovr.gif";
}
}

If I refresh the page(s) in question, the page error
goes away. Can you help me correct the 'error in my ways'.

Regards,
Toe Cutter.
  #6 (permalink)  
Old September 26th, 2007, 01:31 AM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I don't see why this would throw an undefined error. What's the exact text of the error message you're getting, Toe Cutter?

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined index junemo Pro PHP 8 October 31st, 2007 05:45 PM
How to know a variable is undefined? Edward King Javascript How-To 3 June 14th, 2005 10:14 AM
undefined variable !! cody44 Beginning PHP 3 January 20th, 2005 05:47 PM
Undefined Variable fpolan Beginning PHP 9 July 15th, 2004 06:24 AM
Undefined function dhborchardt Classic ASP Databases 0 June 7th, 2004 03:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.