JavaScript - Javascript Onclick-show Image + Link??
So I opted to use JavaScript & PHP (instead of Flash) to create a sort-of "t-shirt designer" -- basically, it's a gallery-type script that allows users to scroll through t-shirt styles, swap colors, and so on, prior to reaching the actual design tool. And I'm starting to regret.
It's actually working very well so far, except for one thing: I want the t-shirt option that the user selects to link the user to the design tool. The "gallery" already has an image for each possible option that displays whenever the user selects a combination, but I want to make that image is a clickable link. I have no idea where to start -- I know next to nothing about javascript -- and to accomplish this in Flasjh I'd have to start this stupid basic thing all over again from scratch, and it would defeat the point of not using Flash in the first place, so... any ideas or suggestions? Similar TutorialsHey all, I want a background image of a tick to appear in each coloured box in my attached image onclick. When another coloured box is clicked I want the image to show in that one and then hidden in the previous one clicked. There should be no ticks shown on page load. I'm clueless as to how to do this. Here's my code for the image attached: Code: <div class="colour-picker"> <div class="tick-off" id="red" onclick="changeclass();"> </div> <div class="tick-off" id="blue" onclick="changeclass();"> </div> <div class="tick-off" id="black" onclick="changeclass();"> </div> <div style="float: right; margin-right: 6px;">Choose colour:</div> </div> CSS: Code: .colour-picker { float: right; margin: 0 10px 0 0; line-height: 30px; text-shadow: #292929 2px 1px 1px; font-size: 15px; color: #FFF; padding: 0px; height: 32px; font-weight: normal; } .colour-picker #red { background-color: red; width: 20px; height: 19px; display: block; margin: 6px 2px 8px 2px; float: right; } .colour-picker #blue { background-color: blue; width: 20px; height: 19px; display: block; margin: 6px 2px 8px 2px; float: right; } .colour-picker #black { background-color: black; width: 20px; height: 19px; display: block; margin: 6px 2px 8px 2px; float: right; } .colour-picker .tick-off { background-image: none; } .colour-picker .tick-on { background-image: url(images/colour-tick.png); background-repeat: no-repeat; background-position: center center; } Can anyone tell me how to do it? Thanks! Adam I have a page where it has anchors going to different parts of the page and i have a list of links at the top to go to each anchor. when you click on the links to each part of the page it shows the "back to top, next, back" buttons. I have 7 different links, so i need to have this happen 7 times, I only want the "back to top, next, and back" buttons to be shown when the user clicks on the link to that specific anchor, or the next/back button to that anchor from another one. I have been doing this with the div hide/show javascript however it makes me have to change sooo much information to do this.. There has got to be an easier way.. It would take me forever to finish doing this to all of them, i need a better way to achieve this. There's too much code that its confusing. this is my current javascript: var ie = (document.all) ? true : false; function hideID(objID){ var element = (ie) ? document.all(objID) : document.getElementById(objID); element.style.display="none" } function showID(objID){ var element = (ie) ? document.all(objID) : document.getElementById(objID); element.style.display="block" } And this is just one of the links: <li><a onclick="showID('1939top'); showID('1939next');hideID('1940top'); hideID('1941top'); hideID('1942top'); hideID('1943top'); hideID('1944top'); hideID('1945top');" href="#1939">1939</a></li> And this is one of the back to top/next button codes: <a href="#1940"><span id="1939next" class="next-back" onclick="hideID('1939next'); hideID('1939top')"><div class="arrow-down"></div></span></span></a> <a href="#top"><span id="1939top" class="timeline-b2top" onclick="hideID('1939top')">Top</span></a><a name="1939" id="1939"></a> This code has always been a huge problem for me, not only does it take forever to change the effects and all, but it is VERY messy and I really need some help on how to code it lol. Thanks so much. Is there any way to make a link show if javascript is being used to hide it? This is the javascript code that is hiding the link: Code: <a href="javascript:void(0)" class="show-hide-link action-link"> Ok so I have a problem which I previously thought I had solved. I am creating a JavaScript Toggle off and on panel and although I have the code sussed for the toggling function there is something off on the image swap function I currently have it set up on two panels, so the code is used multiple times, the problem is it changes both buttons each time rather that just the one that was clicked. Anyway let's see what you think Javascript: Code: <script type="text/javascript"> var imageURL = "../images/portfolio/open.png"; function changeImage() { if (document.images) { if (imageURL == "../images/portfolio/open.png") imageURL = "../images/portfolio/close.png"; else if (imageURL == "../images/portfolio/close.png") imageURL = "../images/portfolio/open.png"; document.images["img1"].src = imageURL; document.images["img2"].src = imageURL; } } </script> HTML: Code: <a href="#" onclick="toggle_visibility('job1');"><img name="img1" src="../images/portfolio/open.png" onClick="changeImage();"></a> <a href="#" onclick="toggle_visibility('job2');"><img name="img2" src="../images/portfolio/open.png" onClick="changeImage();"></a> Any idea what I have done wrong and why it is changing both of the images ('img1' and 'img2') instead of changing them seperately as they are clicked ?? Hi Guys, I am trying to make a change to my website so when someone clicks on the chinese flag image, for example, a function which put the clock forward a few hours. This is what the code I have got at the moment: <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=en'; ?>"><img src="images/uk.gif" title="english" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=zh'; ?>"><img src="images/ch.gif" title="chinese" onclick="chinatime()" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=ja'; ?>"><img src="images/jap.gif" title="japanese" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=kk'; ?>"><img src="images/kaz.gif" title="kazakh" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang='.$most_preferred; ?>">Browser Set</a></td> </tr> <tr> <td colspan="5"> <p class="meta"><span class="date"><script type="text/javascript"> var currentTime = new Date() var minutes = currentTime.getMinutes() var hours = currentTime.getHours() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() function chinatime() { hours = hours + 5 } if (minutes < 10) minutes = "0" + minutes document.write(day + "/" + month + "/" + year + " " + hours +":"+minutes) </script> Many Thanks Hi, i want to bring image download link to download a single image using like <a href="./images/sam.png">Download</a> when i click the download link it need to download plz help how can i download can finished Thanking you Alright, me having a very basic knowledge of js I'm looking for some help with(what I think should be) a simple hide/show of a set of divs. I've broken down the ccs/html I'm looking at on a test page here - http://www.grinnbarrett.net/test.html The js I have in the page had been what I tried to modify from a simple hide/show, but it's not doing what I want it to do (obviously). The goal is when you click on link 3, I want white3 to hide and all the other white divs to show, when you click on link 3, white 2 will hide and the other white divs will show, and so on. So basically it's revealing what div you click to. A lot of what I've found have been just toggles, but I'm not very confident in my ability to adjust code. Any and all help would be appreciated. Hi there, I have a site which consists of the html page and css page. I have been trying to get the image at the top of the page to dissapear when the user clicks on the footer. Any suggestions on how I can do this? Below is my code, Thanks in advance. HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JavaScript</title> <link href="css/main.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { background-color: #CC6; } </style></head> <body> <div id="header-wrap"> <div id="header-container"> <div id="header"> <h1>JavaScript</h1> </div> </div> </div> <div id="ie6-container-wrap"> <div id="container"> <DIV STYLE="font-size:12pt" onmouseover="this.style.fontSize='16pt'" onmouseout="this.style.fontSize='12pt'"> <div id="content"> <h1>Mainframe</h1> <p>Enter the content of your website within this area.</p> </div></DIV> </div> </div> <div id="footer-wrap"> <div id="footer-container"> <div id="footer"> <center> <body onLoad="dateandtime()"> <script> var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") var montharray=new Array("January","February","March","April","May","June","July","August","September","October","Novem ber","December") function getthedate(){ var mydate=new Date() var year=mydate.getYear() if (year < 1000) year+=1900 var day=mydate.getDay() var month=mydate.getMonth() var daym=mydate.getDate() if (daym<10) daym="0"+daym var hours=mydate.getHours() var minutes=mydate.getMinutes() var seconds=mydate.getSeconds() var dn="AM" if (hours>=12) dn="PM" if (hours>12){ hours=hours-12 } if (hours==0) hours=12 if (minutes<=9) minutes="0"+minutes if (seconds<=9) seconds="0"+seconds var cdate="<small><font color='#87ac6d' font size='2.5' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn +"</b></font></small>" if (document.all) document.all.clock.innerHTML=cdate else document.write(cdate) } if (!document.all) getthedate() function dateandtime(){ if (document.all) setInterval("getthedate()",1000) } </script> <span id="clock"></span> </center> </div> </div> </div> </body> </html> CSS: body { font: 62.5% Arial, Helvetica, sans-serif; color: #597347; margin: 0; padding: 0; background: #beffbf; } h1, h2 { color: #87ac6d; font-family: Tahoma, Arial, Geneva, sans-serif; margin: 20px 0 10px; } h1 { font-size: 2.5em; } p { margin: 10px 0; padding: 0; } blockquote { font-style: italic; } #header-wrap { position: fixed; top: 0; left: 0; width: 100%; } #header-container { height: 90px; background: url(../images/banner.jpg) repeat-x left bottom; } #header { width: 940px; margin: 0 auto; position: relative; } #header h1 { color: #beffbf; text-align: right; width: 290px; margin: 0; position: absolute; left: 476px; top: 32px; } #header h1 em{ color: #90b874; font-size: small; display: block; } #header ul { margin: 0; padding: 0; list-style: none; position: absolute; top: 35px; right: 0; } #header ul li { float: left; margin-right: 5px; } #header ul li a{ color: #90b874; font-weight: bold; font-size: 1.4em; margin-right: 5px; text-decoration: none; } #header ul li a:hover { color: #beffbf; } #container { width: 940px; margin: 0 auto; font-size: 1.4em; overflow: auto; padding: 90px 0 40px; } #content { float: left; width: 100%; } #sidebar { float: right; width: 275px; margin-top: 10px; } #footer-wrap { position: fixed; bottom: 0; left: 0; width: 100%; } #footer-container { height: 40px; background-color: #000; } #footer { width: 940px; margin: 0 auto; position: relative; } Hey all Quick question, how do I create a onclick show item? For example, if I am creating a FAQ page and want it to show the question, and then click on the question to have the answer appear below the question, how would I do that? Any examples for this type of thing? Thanks hello.... i am needing help writing a function that when onclick it shows a specific element id and hides all the rest of the the ids i have php code that shows a list of colored boxes and when you click one it changes the color of a div... this works fine as i have used a changecss function... i have these colors in a database with their values and specific color names... what i am trying to do is when a color is clicked it will change the div and also print the color name.... i have made a php loop to print all the color names and i have the display as none... how can i add to the onclick function that changes the color to also put the display of the certain color name to "block" and then if you select another color it hides that one and shows the new color... any help is appreciated! i'm sorry if this is confusing Hey guys, I'm new to the forums, so if i post anything wrong let me know. I'm trying to use links to hide all the images, and show just ones from a certain category. I've used the img name attribute to group them and tried to do a function that shows only one img. here's the script... <script language="javascript"> function showone(x) { document.getElementByName('a').style.display='none'; document.getElementByName('b').style.display='none'; document.getElementByName('c').style.display='none'; document.getElementByName(x).style.display='block'; } </script> and the code... <a href="#" onClick="showone('a'); ">show CAT. A</a><br> <a href="#" onClick="showone('b'); ">show CAT. B</a><br> <a href="#" onClick="showone('c'); ">show CAT. C</a><br> <a href="#">show all cats</a><br> <br> <img name="a" src="imgs/a1.jpg" /><br> <img name="b" src="imgs/b1.jpg" /><br> <img name="a" src="imgs/a2.jpg" /><br> <img name="a" src="imgs/a3.jpg" /><br> <img name="b" src="imgs/b2.jpg" /><br> <img name="c" src="imgs/c1.jpg" /> Here's what it looks like... http://mattfalcone.com/tests/showhide.html except the links don't work like they should, and I can't figure out why. I'm an idiot with javascript, so if feel free to make fun of me, and if anyone knows how to get this simple function to work, please let me know and I'de appreciate it. Hi, I have 4 radio buttons with separate div(s) I need to click on each radio button to show particular div(s) but I am not getting correct result Lease help HTML Code ---------- <input type="radio" name="list_prefer_c" id="list_prefer_c" value="1" onClick=\"get_radio_value(1);\" > <input type="radio" name="list_prefer_c" id="list_prefer_c" value="2" onClick=\"get_radio_value(2);\" > <input type="radio" name="list_prefer_c" id="list_prefer_c" value="3" onClick=\"get_radio_value(3);\" > <input type="radio" name="list_prefer_c" id="list_prefer_c" value="4" onClick=\"get_radio_value(4);\" > <div id="div1" style="display:none"> Facilities Management </div> <div id="div2" style="display:none"> <div style="font-weight:bold">Facilities Management, Contracting, MEP, Hydraulic Valves, trading etc… </div> <div id="div3" style="background-color:#00B0F0;display:none"> Facilities Management, Contracting, MEP, Hydraulic Valves, trading etc… </div> <div id="div4" style="background-color:#00B0F0;display:none"> Facilities Management,Contracting, MEP, Hydraulic Valves, Plumping, LV Switching, Fire alarm & Fire Fighting Trading etc… </div> JSCode -------- function toggleLayer(val) { if(val == 1) { document.getElementById('div1').style.display = 'block'; document.getElementById('div2').style.display = 'none'; document.getElementById('div3').style.display = 'none'; document.getElementById('div4').style.display = 'none'; } else if(val == 2) { document.getElementById('div1').style.display = 'none'; document.getElementById('div2').style.display = 'block'; document.getElementById('div3').style.display = 'none'; document.getElementById('div4').style.display = 'none'; } else if(val == 3) { document.getElementById('div1').style.display = 'none'; document.getElementById('div2').style.display = 'none'; document.getElementById('div3').style.display = 'block'; document.getElementById('div4').style.display = 'none'; } else if(val == 4) { document.getElementById('div1').style.display = 'none'; document.getElementById('div2').style.display = 'none'; document.getElementById('div3').style.display = 'none'; document.getElementById('div4').style.display = 'block'; } } I have a php page that essentially builds a pay report in the form of a table. The php side builds the page properly, though it took some time to get the table rows onmouseover and onmouseout functions to work for row highlighting. Now the issue is the table row's onclick function. Here is what the outputed html looks like. Code: <head> <script type="text/javascript" language="javascript"> function HideShowDiv(divID) { if (document.getElementById(divID).style.display == "none") { document.getElementById(divID).style.display = "block"); document.writeln("show "+divID); } else { document.getElementById(divID).style.display = "none"; document.writeln("hide "+divID); } } </script> <STYLE> <!-- tr { background-color: transparent} .normal { background-color: transparent } .highlight { background-color: #dcfac9 } //--> </style></head> <body> <!-- Start the main body DIV tag --> <div id="PageBodyFrame" align="center"> <table width="80%"> <tr><td colspan="4">Georgetown Youth Baseball Association</td></tr> <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" onClick="HideShowDiv('HD1');"> <td align="left">James Beach</td> <td align="center">1 Game(s)</td> <td align="right">$22.5 owed</td> <td align="center"><a href="pay_report.php?t=l&l=3&act=check&u=1">Cut Check</a></td> </tr> <!-- First hidden div embedded in the next row of main table --> <tr><td colspan="4"> <div id="HD1" style="display:none;"> <table><tr> <td align="center">Game Date</td> <td align="center">Teams</td> <td align="right">Fee</td></tr> <tr> <td align="center">2011-08-06</td> <td align="center">Marin vs LBF</td> <td align="right">\$22.50</td> </tr></table></div></td></tr> <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" onClick="HideShowDiv('HD3');"> <td align="left">John Carpenter</td> <td align="center">0 Game(s)</td> <td align="right">$1.5 owed</td> <td align="center"><a href="pay_report.php?t=l&l=3&act=check&a=3">Cut Check</a></td> </tr> <!-- Second Hidden div embedded in table row --> <tr><td colspan="4"> <div id="HD3" style="display:none;"> <table><tr> <td align="center">Game Date</td> <td align="center">Teams</td> <td align="right">Fee</td> </tr> <tr> <td align="center">2011-08-06</td> <td align="center">Assigner Fee</td> <td align="right">\$1.50</td> </tr></table></div></td></tr> <tr> <td colspan="2" align="right">Some Association of Baseball</td> <td align="right">\$24</td> <td align="center"></td> </tr> </table> </div> <!-- Closes the main body div container --> In my javascript function, the writeln() calls are for testing to see if the even is even firing. but nothing gets written to the page. Any thoughts on this would be greatly appreciated. Basically I want the row with the users name to be clickable which will show the details in the hidden div associated with the user. How do I show the default icon for pdf, doc, etc... else show the image? Code: Show the default icon for pdf, doc, etc... else show image. Default icon: '<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' + The image: '<img alt="" src="' + fileUrl.replace( /'/g, '\\\'') + '" height="36" border="0"></a>' + Attempted javascript onError but only certain browsers support that or it's my code. Code: '<img alt="" src="' + fileUrl.replace( /'/g, '\\\'') + '" height="36" border="0" onerror="this.src=images/icons/' + sIcon + '.gif"></a>' + Any ideas? hi all im trying to hide a div on page load, ive used this. Code: <script type="text/javascript"> function hideDiv(){ document.getElementById('sidebar').style.display = "none"; } hideDiv() </script> and this in the body tag Code: <body onload="javascript:hideDiv()"> it works fine hiding the div named sidebar, problem comes when i try to then use an Onclick event to show the hidden div, it just wont show. can this be done? please help if you can this work has to be in soon Hey guys, I have this JS. Code: function funcBut(){ document.getElementById('ref_button').innerHTML = 'pressed'; } Now, this button activates the function with no problem: Code: <input type='button' onclick='funcBut();' value='Change Text'/><br /> But this link won't work and I don't understand why Code: <a href="#" onclick="funcBut(); return false;">test</a><br /> Can anyone help? I'm looking for a simple code to perform this function I'm 3/4 of the way there but need some help. I have a static GIF that is swapped for an animated gif after an onclick event. I want the animated gif to have a clickable URL that is activated once the user clicks on the static GIF. Here is the current code I have to show the animated gif from the onclick event, how do I add a web site URL to make the animated.gif a clickable image link? Code: <img src="static.gif" width="620" height="549" onclick='javascript:(this.src=="static.gif"?this.src="animated.gif":"")' /></a> I've been doing some searching and I can't seem to find what I am looking for. I hope someone can help. I am trying to target a link to an iframe window. The catch is that I need to use an onClick function in a TD tag... Here is an example: <TABLE HEIGHT="40" WIDTH="780" CELLSPACING="0" CELLPADDING="0" BORDER="1"> <TBODY> <TR> <TD ALIGN="CENTER">HEADER 1</TD> </TR> <TR> <TD OnClick="location='http://www.ophil.com'" BGCOLOR="#FFFFFF">Ophil</TD> </TR> </TBODY> </TABLE> </TD> </TR> <table width="100%" border="0" cellspacing="0" cellpadding="1"> <tr> <td><a name="bidframe"> <IFRAME SRC="bid_item_instructions.html" TITLE="IFRAME" SCROLLING="no" NAME="bidpage" WIDTH="100%" HEIGHT="450" ALIGN="center" FRAMEBORDER="yes" > </IFRAME> </a></td> </tr> </table> </CENTER> </BODY> </HTML> I need the results of that onclick to appear in the iframe window I have called bidframe... Any ideas? this is my html page.. Code: <html> <head> <script type="text/javascript" language="JavaScript"> function general_formats() { window.open('http://www.test.com/general_formats.php'); } </script> </head> <body> <a href="general_formats.php"><onclick="general_formats(); return false">General Formats</a> </body> </html> When i click ' general Formats ' , a window is opened , i dont need that . What i need is , when i click the link , it should direct to general_fomats.php.. please help me to solve it . .any help will be appreciated . |