Is it possible to use images as javascript variables?
Howdy,
I here’s wondering if it is possible to make a good image a javascript variable, and if that’s the case how does one do it We are wondering the same thing concerning javascript arrays.
The images i always would be using would be from the same folder since the HTML insurance coverage if this helps.
Here’s kind of an example of what I’m trying to do.Certainly whatever this particular code here does can be pretty dull, I’m merely giving an example of how I’d like to use the concepts.
This example also demonstrates how I would use the different pieces involving code that you see from the example.So in the event you see virtually any syntax glitches or utilization errors generally, please well then , i’ll know.I am new for you to javascript.I am especially concerned about my us going for document.getElementById because I am not entirely sure tips on how to use that, but Relating to heard that it provides multiple advances over using insurance coverage.write.
Thanks earlier and WHEN I DO prefer to pick a best solution.
-JDDellGuy
Hmm, You can hold your address of the image for a variable as follows
var photo = “C:\image1.jpeg”;
Now in order to show the image from the page, only
var img = fresh Image();
img.src=pic
insurance.body.appendChild(img);
Certainly, document.getElementById would certainly require of which an id be in the variable
Permits suppose the particular id will be  
Right now document.getElementById(“image”).append Child(img);
would include an image in the webpage when
  is situated in the HTML Code
You can’t assign an ID to your variable, you can only assign ID to the fields in HTML.These ID’s can be latter used to retrieve on line casinos of the actual field.Suppose
would likely display the textbox.
Now if you want the value which can be typed while in the textbox then you need to use
var name = document.getElementById(“name”).value;
Important thing, I think this is what you will need (MODIFIED)
Graphic is below:
Many thanks, Hope the idea helps.Please publish back if you want more assistance.
Hi, I’m also a little bit new to javascript thus this is probably not the best solution, by ive observed that the easier just to give this image some sort of name for example the html can be then in the script as an alternative to getElementById take document.pic1.src=”pic1.jpg” in addition to itll just simply replace this default…idk in the event this solutions your problem, hope the idea helps
I’m simply no JavaScript skilled either, nevertheless , you could make your own personal object for handling metadata regarding images.
Now you can access the particular pic1-objects areas path plus color by using pic1.route and pic1.colour.For example
in the event (pic1.colour == “green”)
insurance.write(“pic1 is actually green! here it really is:“)
Leave a Reply
You must be logged in to post a comment.