Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


JavaScript Programming

JavaScript > Code Examples

Access Image URL to TextBox

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
Access Image URL to TextBox When an image is clicked, this script will show the image URL in a textbox. Useful for cases where you want others to be able to copy the image address easily for linking... such as for banners, logo graphics, etc. A single instance of the script can be attached to any number of images in the page. --------------------- Paste the following script into the <head> ... </head> of your page. There are no script set-ups needed. <script language="JavaScript"> var isReady = false; function showAddress(What){ if (isReady){ document.Which.Where.value = What; document.Which.Where.focus(); document.Which.Where.select(); }else{ alert("This page is not fully loaded yet...\nPlease wait for the page to finish loading."); } } function clearAddress(){ if (isReady){ document.Which.Where.value = ''; }else{ alert("This page is not fully loaded yet...\nPlease wait for the page to finish loading."); } } </script> The Body Tag Onload Event ------------------------------------ Add onload="isReady=true" to your body tag, as shown below. This is necessary to prevent false object calls prior to the page being fully loaded. Thus: <body onload="isReady=true"> The TextBox ------------------------- Insert the following code for the text box in your page. (It may be anywhere in your page.) Do not change the form or field names. <form name="Which"> <input type="text" size="60" name="Where"> </form> To clear the textbox from a link in the page, use this: <a href="#" onClick="clearAddress()"> Clear </a> Step Four: Attaching To The Images ----------------------------------- You may attach the script to as many images as you wish. To attach to the image add onMouseDown="showAddress(this.src)" to the img src tag, as shown in the sample below. <img src="http://happycodings.com/image.gif" width="100" height="100" border="0" onMouseDown="showAddress(this.src)"> Note that you can use either the explicit http:// address of the image, or just a relative address to the image file. In the later case, it will still return the full http path to the image in the text box.