473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to put an image over a value using javascript

11
i'm working on a minesweeper game and i don't know how to replace an image (=any button was clicked)by the value suppose to be under it.
(i have already all the functionality of bombs and neighbors and 10*10 images of buttons - but i can display this or this- not they both at once and this is another question - how to put the numbers and bombs under the button images...)
i'll be glad to get some help,thanks in advance.
Aug 1 '11 #1

✓ answered by Rabbit

This will change the image with ID Pos0905 with a new image. This will probably use the onclick event of the image. Do your checks and then replace with the appropriate image.
Expand|Select|Wrap|Line Numbers
  1. document.getElementByID("Pos0905").src = "bomb.png";
You can overlap elements by using absolute or fixed positioning. But in this case. I would just suggest creating images for the 9 numbers, then you don't have to overlap elements, you just have to change the source of the image.

4 2172
Rabbit
12,516 Expert Mod 8TB
This will change the image with ID Pos0905 with a new image. This will probably use the onclick event of the image. Do your checks and then replace with the appropriate image.
Expand|Select|Wrap|Line Numbers
  1. document.getElementByID("Pos0905").src = "bomb.png";
You can overlap elements by using absolute or fixed positioning. But in this case. I would just suggest creating images for the 9 numbers, then you don't have to overlap elements, you just have to change the source of the image.
Aug 1 '11 #2
yiskas
11
Thanks,
But i realy don't know what is "Pos0905".

-I tried doing this: document.getElementByID("bomb").src = "bomb.png";
and i get an error massage:"Uncaught TypeError: Cnnot read property 'src' of null"

Why is that?
Aug 2 '11 #3
Rabbit
12,516 Expert Mod 8TB
This is sample code, it's not meant to just work because I don't know your setup. In the example, Pos0905 is the ID of an image. A name I made up to identify the different squares in an array of images. The error is probably because you don't have an element with the id bomb that has an attribute src.

If you're having trouble understanding the code, you should look into a javascript tutorial before you start the project.
Aug 2 '11 #4
yiskas
11
thank you thank you, you were very helpful and gave me ways i can think of.תודה
Aug 3 '11 #5

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

Similar topics

4
by: zborisau | last post by:
Hey good people, I've been given a problem to solve recently - and stuck with the solution for a good 4 days already. i have a link which leads to popup window. the purpose of that popup...
3
by: chrispragash | last post by:
Hello All, This may be a silly question to ask - but for some reason I am unable to get this to work! I have a server control that renders a Label and a linkbutton, and I have a Javascript...
4
by: Doug van Vianen | last post by:
Hi, I have the following coding on a web page. It causes two pictures (pic1.jpg and pic2.jpg) to show, one above the other and then when one clicks on the top picture is squeezes to the left...
5
by: jose1lm | last post by:
What is supposed to happen: A user enters data into one of the FORM input selections. When the user submits the form, the onclick event is supposed to go to a function that will set another FORM...
6
by: sagarlotiya | last post by:
Hi I have made one javascript which allows me to add note on image using css and javascript. Every thing works fine. But following problme occurs. I want to display allthe notes on image when we...
1
by: sumanthdivvela | last post by:
<select name="cityName" class="CLiKSformfield" id="IdfbCity" onChange="javascript:addCity(this);"> <option value="ALL">Select Location</option> <option value="1001" >...
5
by: plsHelpMe | last post by:
Hi Frens, I want to show a blank space at the begining of the option tag using javascript, can anyone please help me for the same. Let me explain what i want: I want to have an event which the...
3
by: sejal17 | last post by:
Hello I have got image path in javascript from php code. That is:http://localhost/fotolia/photos/9.jpg I want to take only photos/9.jpg from that full path.How can i do that?Please...
4
by: phpmagesh | last post by:
Hi I am using php and smarty, what i have to do is i have a drop down box with dynamic name, id and values. like <select name="id" id="id" onchange="sample()" > {foreach key=key_data...
8
donilourdu
by: donilourdu | last post by:
hi, I want to preload the image on page load using javascript by, Doni
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.