473,699 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing "img" of img.src as argument

3 New Member
Ok, so, this is my first post, if there is any info i am leaving out please tell me

this is the function:

Expand|Select|Wrap|Line Numbers
  1. function mouseOver(c)
  2. {
  3.     alert(c);  <!-- just for debugging-->
  4.  
  5.     if (c.src == "red.jpg")
  6.     {
  7.         document.c.src = "black.jpg";
  8.     }
  9.     else if (c.src == "black.jpg")
  10.     {
  11.         document.c.src = "yellow.jpg";
  12.     }
  13.     else if (c.src == "yellow.jpg")
  14.     {
  15.         document.c.src = "red.jpg";
  16.     }
  17. }
this is how i made the images:

Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i <= 27; i++)
  2. {
  3.     for (j = 0; j <= 55 ; j++)
  4.     {
  5.         document.write('<a href = "redbluegreen.html"> <img src ="red.jpg" border = "0" width = "20" height = "20" name = p onmouseover = "mouseOver(name)"> </a>');
  6.         document.p.name = namer(i,j);
  7.     }
  8.     document.write('<br />');
  9. }
and heres the namer function:

Expand|Select|Wrap|Line Numbers
  1. function namer(i, j)
  2. {
  3.     return "r" + i + "c" + j;
  4. }
now, what it does is create a 55x27 matrix of squares, when you mouseOver each square the idea is that it will change to the next color, I am passing the name of the image along to the mouseOver function. When I mouse over the image my alert(c) is telling me, correctly, the name of the square (i.e. r10c7) but the src of the image it tells me is unidentified when I modify the alert to alert(c.src). What I am thinking is that it is passing the name of the image to mouseOver as a string, but i'm not sure why this is a problem because I thought thats what the names of images always were. Any help would be greatly appreciated.

I know c++ reasonably well, but not javascript, I think I may be missing something as far as var goes i'm used to int double string and whatnot, also I have attached the full source if that is helpful
Attached Files
File Type: txt parlour.txt (1.1 KB, 383 views)
Feb 5 '09 #1
5 3082
Dormilich
8,658 Recognized Expert Moderator Expert
a name is not a unique identifyer, better use id for that (along with getElementById( )). probably the best is using the "this" keyword (then you wouldn't even require the name).
Expand|Select|Wrap|Line Numbers
  1. if (this.src == "red.jpg") { ... }
Feb 5 '09 #2
enaz
3 New Member
OK, I now have the argument passed in correctly so that i can identify the src of the img, however, i'm not sure how to edit that src (i used getElementById( c)) to find the src) i assume i could use this.src to edit it, but in the scope of the function this.src is not defined, is there a way to make this = img or somehow pass this to the function?
Feb 5 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
the this variable is defined when the function is attached to the element (i.e. when the function becomes a method of the used element object).
Expand|Select|Wrap|Line Numbers
  1. mouseOver(); 
  2. // "this" is undefined
  3.  
  4. element.addEventListener("mouseover", mouseOver, false);
  5. // "this" = element
Feb 6 '09 #4
enaz
3 New Member
thank you very very much, i got it working!
Feb 6 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
always a pleasure to be of help
Feb 6 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

14
13075
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in - ImageName - for processing, or the return data which is done (or not as the case may be) by imagejpeg($img) in the script, after header("Content-type: image/jpeg"). Any insights would be most welcome, especially debugging techniques and a pointer to...
3
1377
by: Alias | last post by:
dynamically creating a number of thumbnails, which is working fine. However, they are supposed to call a function loadRightFrame when clicked, and I seem to be running into syntax problems. This code: pagecontent+='<img width="70" height="70" border="0" src="' + thumbArray + '" onClick="loadRightFrame(\"' + photoArray + '\")">' resolves to this:
2
1561
by: windandwaves | last post by:
Hi Folk I have the following function var a = new Array(4); a = new Array(45); //status (on or off) a = new Array(45); //name of the region a = new Array(45); //on mouse over a = new Array(45); //on mouse out a = false;
8
10641
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at the same time and set different values? Thank you for suggestions!
9
1894
by: Burak Gunay | last post by:
Hello, In my asp.net 2.0 page, I have a hyperlink with an arrow image <a id="imgtest" href="#"onclick="return hideColumn()"> <img id="imgArrow" src="App_Themes/Trmis/WebResource3.gif" alt="Click" /> </a> WebResource3.gif is an arrow pointing left and when I click on it I
7
4816
by: bookon | last post by:
I was running into the System.Drawing.Image.FromStream "parameter is not valid" on some of the images I was retrieving from a blob column in Sql Server. I thought there were corrupt images as almost all worked (all are gifs), and only a few broke when this line ran: Image img = Image.FromStream(ms); here is the original code: b = (byte)dt.Rows.ItemArray; //b.ToString() ms = new MemoryStream(); ms.Write(b, 0, b.Length);
8
9266
by: fredo | last post by:
This question was asked in comp.lang.javascript with no result. In IE5.x and IE6, I want to display an image when the user rolls over a text link. The image does indeed display, but only on the first rollover. It seems that the image height and width become set to zero after the image is displayed once; or perhaps that the height:expression(eval(...)); code is executed only once for each page load/reload. problem demo:
3
19569
by: SkyZhao | last post by:
i use attachEvent to bind a event ; code: img.attachEvent("onclick",alert("aa")); div.appendChild(img); div.innerHTML+="some text"; the event can not work; why can't i use it? if i use nether code , it can work;
4
23904
by: tswaters | last post by:
Alright, so generally I'm using document.createElement("IMG").... but, I've noticed something just recently that made me switch to "new Image()" What I'm doing is creating a photo gallery of sorts, where i basically want to supply a total # of images, rows/cols max thumb/full image and let the script do the work. The solution I've opted for is to load the images once and change their size / position / visibility to show "thumb galleries" or...
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
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
8880
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
6532
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
5869
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
4373
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...
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
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.