Jump to content

help javascript change AVAILABLE


quanpq

Recommended Posts

function change_color(color) {  document.getElementById("t_shirt").src = "/images/"+color+"/.jpg";}

Then find elements in html for these to boxes, white and gray and put function onclick=java script: change_color('white'); and same for gray.Also. You can change location of files in js code above, or put your images to /images/ folder with names white.jpg and gray.jpgThen you must name div or some element with id=t_shirt, or change it in function.

Link to comment
Share on other sites

what do you have so far? it might take a combination of PHP and Javascript. PHP could write the script for each page so that when a given color sqaure for an item is clicked, the script will already know the right image to swap it with. Really depends on your setup and what code you have so far.

Link to comment
Share on other sites

there's no need to double post, and surely you can wait longer than a half hour for a response. You should just stick with one forum and go with it. I'm sure a mod will merge this shortly.

Link to comment
Share on other sites

thanks Haris S helphave folder images 2 filelaptop_white.jpglaptop_black.jpg1.jpgafter onclick2.jpgcode html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script>function change_color(color) { document.getElementById("t_shirt").src = "/images/"+color+"/.jpg";}</script></head><body><img src="images/laptop_white.jpg" id="t_shirt" /><a href="#" onclick="java script:change_color('laptop_black')">color black</a></body></html>

Link to comment
Share on other sites

Try this linedocument.getElementById("t_shirt").src = "/images/"+color+"/.jpg";todocument.getElementById("t_shirt").src = "images/"+color+"/.jpg";Maybe, location isn't good.

Link to comment
Share on other sites

help

no run file<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script>function change_color(color) { document.getElementById("t_shirt").src = "images/"+color+"/.jpg";}</script></head><body><img src="images/laptop_white.jpg" id="t_shirt" /><a href="#" onclick="java script:change_color('charger')">color black</a></body></html>
Link to comment
Share on other sites

Are your images really called ".jpg"? Are you sure you don't mean:

document.getElementById("t_shirt").src = "images/"+color+".jpg";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...