Jump to content

help javascript change AVAILABLE


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 post
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.

Edited by thescientist
Link to post
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.

Edited by boen_robot
Topics merged...
Link to post
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>

Edited by quanpq
Link to post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...