function not defined?

Discussion in 'JavaScript' started by neridaj, Jun 20, 2008.

  1. #1
    Hello,

    I don't understand why this function is not defined:

    		function swapimg(in)
    		{
    			alert(in);
    			var imgname;
    			imgname  = in;
    			window.parent.document.getElementById('ifrmtarget').src="images/" + in + ".jpg";
    		}
    Code (markup):
    I'm calling it like this:

    <a href="#" onclick="swapimg(00)" >

    If you see the problem, would you please let me know.

    Thanks,

    Jason
     
    neridaj, Jun 20, 2008 IP
  2. zacharooni

    zacharooni Well-Known Member

    Messages:
    346
    Likes Received:
    20
    Best Answers:
    4
    Trophy Points:
    120
    #2
    Is this in a <script type="text/javascript"></script> tag in the <head></head> ?
    Also, try calling with:

    <a href="#" onclick="javascript:swapimg(00)" >
     
    zacharooni, Jun 20, 2008 IP
  3. chaosprime

    chaosprime Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try loading your page in Firefox and viewing the contents of the JavaScript console window (type javascript: into the location bar). It may tell you the error that's making the function undefined.
     
    chaosprime, Jun 20, 2008 IP
  4. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Please change like bellow:
    1. Put the swapimg() in the parent page which has "ifrmtarget" and use document.getElementById('ifrmtarget').src =".." in swapimg()
    2. In main page, set window.swapimg = swapimg; right after the your function definition
    2. In the sub page loaded in main page, you can refer to swapimg() function by calling window.parent.swapimg("..");
     
    koolman, Jun 20, 2008 IP