HTML - Replacing Button With An Image
I have a small image (icon) which when clicked will take you to one of x number of sites via a random link generator.
Here is my html where randomlink refers to a javascript routine in the head. <form> <p><input type="button" name="B1" value="Random Link >>" onclick="randomlink()"></p> </form> This works fine in returning a random website (actually one from a list). But I would like to replace the button with an image. I tried this but no joy: <form> <input type="image" onclick="randomlink()" value="Random Link >>" src="../images/icon.jpg"> </form> What am I doing wrong? Hugh Similar TutorialsHi anyone who could help ! In the following code by clicking on the right bottom corner of the image, a link to the destination site occurs. <img src="images/4ticket.jpg" border="0" usemap="#Map" width="203" height="90"> <map name="Map"> <area href="www.destination/play.php" shape="rect" coords="72, 56, 185, 77"> </map Now I would like to replace the link with a form submit button, as I need the value of the submit button (Play FREE!) to be posted to the destination site. Thanks for any help or hint Hi, I have a website where i am reselling. They use fixed templates so its easy to use but they include header and footer html boxes so that you can put in your own code. I have used these boxes to change my background and font colour however there are a couple of images on there that are now the wrong colour and i cant seem to figure out code to change these images, just add to them. Does anyone know of any code that replaces one image with another? thanks! Chris This thread; plain and simple.. I want the following tags: HTML Code: background-image:url(blokje.png); background-image:url(onderkant%20curve.png); Replaced with something like this: HTML Code: <img id="pic" src="top.png" alt=""> Why? Because the top.png image is the only image that loads correctly when mail template is sent to mail recipients. Please advice, thank you. Source: HTML Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <base href="http://asitisinheavenagain.com/"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="language" content="english"> <meta http-equiv="Content-Style-Type" content="text/css"> <title></title> <style type="text/css"> #container{ width:711px; margin:auto; font-family:verdana,sans serif; font-size:16px; background-image:url(blokje.png); } #pic { display:block; } #content { padding:0 0 60px 50px; background-image:url(onderkant%20curve.png); background-repeat:no-repeat; background-position:0 bottom; } #p-one { font-weight:bold; color:#410d3e; } #pic-one { text-align:center; } #pic-one img { width:170px; height:190px; } #link { font-size:12px; } </style> </head> <body> <div id="container"> <img id="pic" src="top.png" alt=""> <div id="content"> <p id="p-one"> Nieuwsbrief Februari 2010 </p><p><br> Beste Lezer van mijn eerste nieuwsbrief, </p><p> Graag wil ik je opmerkzaam maken op de nieuwste activiteiten van <br> Sessio Communications. </p><br> <p id="pic-one"> <img src="koord.jpg" alt=""><br> <a href="http://www.asitisinheavenagain.com">www.asitisinheavenagain.com</a> </p><p> Ik nodig je van harte uit om <a href="http://www.asitisinheavenagain.com">mijn website</a> te bezoeken.<br> Reacties zijn welkom. Doorsturen naar andere belangstellenden mag. <br> <a href="[FORWARDTOFRIEND]">Stuur deze email door naar een vriend of vriendin.</a></p><br> </p><p> Mocht je geen belangstelling hebben om op de hoogte te blijven van<br> mijn verschillende workshops en trainingen dan kun je dat via de <br> link onderaan de pagina aangeven. Je e-mail adres wordt dan verwijderd. </p><p><br> </p> </p> </div> </div> </body> </html> If you view my site: www.vivalefrench.com you can see that I have a few dead image links. And there are a few here and there and it would take a long time to adjust...is there an easy way to add a short piece of code at the top of my index page to detect 404 images and replace them with a standard (noimage.png) file.? I have seen somthing that you can do for each individual image but I'd like to put the code at the top to save time Hey Guys, I am a graphic designer and don't know much about HTML (but am taking a class and about to start a few books). I am using tumblr right now and I am try to replace the automated header ("black atom studio") with a jpg banner. Anyone know where in the HTML I would do this and what code I would need to swap in? (the website I am working at is www.blackatomstudio.com ) (not a plug, just incase you guys need to see what I am talking about) Here is the code I need help on. http://snipplr.com/view/8582/blackatoms-tumblr/ I am creating a website that has a search button with an image. I would like to know if there is some simple code that I can include that would display the same basic image with a different color when the user mouses over the button. Here is the code: <FORM name="searchform" onSubmit="return validateSearch();" METHOD="POST" ACTION="search_results_lt.asp"> <INPUT TYPE="text" NAME="Search" VALUE="" SIZE="20" > <INPUT TYPE=IMAGE SRC="images/search_button.gif" Name="SearchButton" Value="Submit"> </FORM> **** Thanks for your help, Robin So in January 2006 I posted a question about "making two buttons in one" 3 years and 5 months later i am happy to announce that I have found a solution. Ok, so no I have not spent the last three years looking, but the need for one came around again yesterday so I revisited the project. All I needed was "simple" image toggle. Image 'A' click it once it changes to image 'B' click it again it changes back to image 'A' All the "image toggle" codes I could find were extremely complex. I thought I had finally found one, it wasn't perfect, but it was the smallest and most basic thing I could find. HTML Code: <html> <head> <style type="text/css"> .on {background-image:url(playlist_btn.png); background-repeat:no-repeat;} .off {background-image:url(playlist_btn_x.png); background-repeat:no-repeat;} </style> <script language="javascript"> function togglestyle(el){if(el.className == "on") {el.className="off";} else {el.className="on";}} </script> </head> <body> <div id="onoff" class="playlist_btn"><img src="blank.gif" width="50 height="50" onclick="togglestyle(onoff)"></div> </body> </html> I tested it, it worked, so I considered problem solved. I placed it in my page and nothing. Turns out it wont work with a doc type - so it's useless. Other problems, I'm not big on using "blank gif's" unless I have to, if you want multiple image toggles you need a new JS function for each one, and two lines of css as well. And, though I rarely use image rollovers anymore, it would certainly not be possible in this method. So it was back to the drawing board. Well, I had actually already found the solution a few minuets prior to finding out that the above code is so good. I had coded a button that on rollover shows a tooltip, when you click the button, the text in the tool tip, changes, chick again and it reverts. All done with a simple showHide javascript function, that i am finfing out has many uses. here is the awesome code: Code: function showHide(elementid){ if (document.getElementById(elementid).style.display == 'none'){ document.getElementById(elementid).style.display = ''; } else { document.getElementById(elementid).style.display = 'none'; } } function hideShow(elementid){ if (document.getElementById(elementid).style.display == ''){ document.getElementById(elementid).style.display = 'none'; } else { document.getElementById(elementid).style.display = ''; } } I wont take credit for the showHide code, but I will take credit for the hideShow portion, obviously a monkey could have coded the revers, but iot does make it that much more universal. As the original code was designed to show something that was hidden, add the revers to hide something that is showing and it's perfect. Now I will take a moment to say, though I have yet to find a problem with the code, it seems to work in most browsers, firefox, ie, safari, and validates for WC3 - In sure it has it's flaws. Until now, to show and hide divs I had used the MM_showHideLayers JavaScript function, which by default used the visibility style. It is of course a good script, and has many uses, it's not very big, but it is somewhat complex. The other thing to think about is that invisible objects still take up space. That's what is cool about the display:none: style, is that is not only invisible but it doesn't take up space. So here is how I used the above to JavaScript to make a simple onclick image toggle: HTML Code: <img id="on" src="on.png" width="50" height="50" onClick="javascript:hideShow('on'); javascript:showHide('off')" alt="on"> <img id="off" src="off.png" width="50" height="50" onClick="javascript:hideShow('off'); javascript:showHide('plus')" style="display:none;" alt="off"> Cool huh? Now this example does not have a rollover either, but since it uses to individual images and is not replacing one image wioth another you could easily apply a rollover to both images. But, hold on, look at the above code, isn't that essentially a rollover? Change the first onClick to onMouseOver and the second to onMouseOut and look at that a 'brand new' method for mouseovers. So lets take a look at this for a second, and compare MM_swapImage to this new hideShow method. As far as CSS rollovers I definitely prefer them to the MM_swapImage method, as they use a minimal amount of code. However they actually take a lot of math, construction the buttons is somewhat tedious, because css buttons use 1 image and change it's position, to work well you have to use a "blank.gif" and the the css can really add up if you have a lot of buttons: Also, you can't go directly to a button in the document, you have to fish through the css to make any adjustments. But they are fast, they don't need to be preloaded and... they are pretty cool. But anyway, swapImage and hideShow... The left is the MM_swapImage method. Now when you use the swapImage js you also have to use MM_swapImgRestore, MM_findObj, MM_preloadImages. You don't have to use the preload script but it does make thing work faster... supposedly, but that requires a onload script in the body tag, and if you have a lot of rollovers your body tag can get really long really quick. So what are the advantages, well we know for sure it works, and you only need on image in the document, however actualy having the image you are "swapping" too actually in the document can add functionality. So as you can see, on the right, the showHide method is, in total code, much smaller. True you do need to use two images, so the total code in the body is longer but, it's more than evened out bu the minimal JavaScript, and I think it's worth it. You don't need to use a preloader, you have full control over both images, the up and over state, and unlike the swapImage method, though it's rare you would need to, your up and over images can actually be different sizes, which is kind of cool. So here's the basic code for a rollover: HTML Code: <img id="up" src="up.png" width="50" height="50" onMouseOver="javascript:hideShow('up'); javascript:showHide('over')" alt="up"> <a href="http://google.com"><img id="over" src="over.png" width="50" height="50" onMouseOut="javascript:hideShow('over'); javascript:showHide('up')" style="display:none;" alt="over" border="0"></a> To add a link the button you just apply it to the "over state" image. And unlike swapImage, though it is overkill, you can also add a "downstate" image quite easily. So, back to the on/off button here is how you would code it using showHide with rollovers. HTML Code: <img id="on" src="on.png" width="50" height="50" onMouseOver="javascript:hideShow('on'); javascript:showHide('onover')" alt="on"> <img id="onover" src="on_over.png" width="50" height="50" onMouseOut="javascript:hideShow('onover'); javascript:showHide('on')" onClick="javascript:hideShow('onover'); javascript:showHide('offover')" style="display:none;" alt="onover"> <img id="off" src="off.png" width="50" height="50" onMouseOver="javascript:hideShow('off'); javascript:showHide('offover')" style="display:none;" alt="off"> <img id="offover" src="off_over.png" width="50" height="50" style="display:none;" onMouseout="javascript:hideShow('offover'); javascript:showHide('off')" onClick="javascript:hideShow('onover'); javascript:showHide('off')"alt="offover"> So here is what is going on: you have the upstate on.png image, when you mouse over it on.png is hidden and on_over.png is displayed. When you click on_over.png it is hidden and off_over.png is display, mouse off it and off.png is displayed. Make scene? Now be aware, when you click, you are also in a scene "mousing off" so some flickering can occur. Firefox handles everything pretty well, IE and Safari not so much. When you click the on_over.png the click tells it to hide on_over.png and show the off_over.png, at the same time the mouseoff tells it to hide on_over.png and show the on.png. So fortunately the toggle with rollovers isn't perfect, but perhaps some more tweaking of the code or maybe, in this case swapImage would work better to do the rollovers... But all in all I'd say its a solid concept. If you feel compiled to do so, reply with any comments, concerns or flaws you see. I've tried multiple ideas but basically I just want it to be a regular grey button with the dimensions of the image I want to slap on the front of it so it will to a click down animation when someone clicks on it but so far all I get is this... HTML Code: <FORM METHOD="LINK" ACTION="mms://media.huntingtonnews.net/video/2007/BillDargusch-Downtowns-1.wmv"> <BUTTON TYPE="submit"><IMG SRC="http://www.huntingtonnews.net/images/baseball1-tn.jpg" alt="wow"></BUTTON> </FORM> And that is pretty good but the grey parts of the button sticking out make it look horrible. Does anyone know a way to shrink the button to the image size?... Codeguru Hello all. Our Website runs wordpress with a standard header, body and one sidebar template. We need to be able to have an image in the sidebar that when it is clicked, a different image is then opened at the top of the body. Is this possible? Thanks for your time. kevin Hello i need help getting a button to work in my website. It will be a link to another page. I have this html. I have three images.They are gifs. I also have three more in .png. I can make just about any kind of file. When i made the files i used transparency and interlaced. I'll attach images. I want one to appear when to mouse goes over it and one to appear when it's clicked. The attached ones are .png's. thanks I have the following code but the images do not swap: Quote: <input type="image" name="action" value="Submit" src="{site_url}images/submit_a.gif" class="Button" onMouseOver="document.submit_form.src='{site_url}images/submit_b.gif'; return true;" onMouseOut="document.submit_form.src='{site_url}images/submit_a.gif'; return true;" > The {site_url} replaces the site domain name. I have confirmed the the images exist. Any ideas? I am new to HTML. I just started yesterday and found it to be useful so far. I am in the process of setting up a website so I searched for a template to use, but it wasn't complete. I think everything is in place except for the 5 page link buttons on the side. Currently they all link to the same site, but I can fix that myself. I need to put text over the image while still allowing the button to be clicked, but I don't know how. I put an image of what I want inside the attached zip file. Thanks in advance. Hello all, does anyone know a where and what the code is to put a small 2 pixel image between buttons? also, does anyone know some code (if Flash isnt detected) display a Gif, I found one and it works fine in IE but not FF. Thanks Jason Hi I want to be able to turn the image that reads 'back' on the page below into a "back button" that automatically makes the browser go back a page, just like the back button within the browser. How do i do this? http://www.richardjohntaylor.com/bil...hotoerror.html I'd like to improve the appearance of three buttons on an html page. i believe this is the code: Code: <input type="submit" name="purchase" value="Use Remaining Credits" style="margin:7px 0" style="padding:1px 2px 1px 2px" rel="gb_page_center[600, 635] "> <input type="button" name="search" value="Get New Credits" onclick="window.location.href='newcredits.php';" style="margin:7px 0" style="padding:1px 2px 1px 2px"> <input type="button" name="search" value="Search Again Now" onclick="window.location.href='page.php??page=12';" style="margin:7px 0" style="padding:1px 2px 1px 2px"> How can I add more attractive buttons, which would include the text "Use Remaining Credits", etc.? can you please provide a code example, with image code? Thanks Hello, this may sound like a dumb question: Is there a way build a button that on rollover makes an image appear beside it? thanks Hi all i have an upload form, and when the upload button/image is clicked to upload the file, i would like to have this cool ajax loader that just moves with some text under it saying "uploading...please wait". What is the easiest and best way to do this? I have looked all around javascript, etc and cant seem to find a perfect simple solution. I am adding this in my .tpl file THanks Hello, I'm experiencing a small but annoying problem. My html form works fine when the submit button is an "ugly grey button" (input type=button), but when I try changing the button to show a nice jpg (input type=image) the form still submits ok, but the page always jumps to the top. This is annoying, because people should be able to scroll down through the page, click the button, and continue scrolling down to the next button. Many thanks in advance for any helpful explanations or hints! Simon I've followed this walkthrough on how to make a submit button with an image on it. The image part is working fine (along with the mouse up and over images) but the actulle submit function of the button is NOT working. Here is a link to the lession I have been following: http://www.codetoad.com/html/buttons...mit_button.asp And here is a link to the page with the non-working submit button: http://www.acreativeapproach.com/contact.html This is a pretty simple form That was made in DW. Do I need PHP to get a contact form like this to work? Thank you for your help JT Hello, Is there a way to use a submit style button (so HTML automatically generates the button image) instead of having to have a image file? For example: <a href="../invoices.htm"> <img border="0" src="../btn_invoices.jpg" width="73" height="25"></a> where the src is can this be repalced with a button command? without using a FORM or POST option? Something similiar to: <button> <a href="http://www.microsoft.com/">Microsoft</a> </button> Thanks for your help, Doug |