JavaScript - Change From Image To Text.
Code:
function greet() { var hour = (new Date()).getHours(); var when = (hour > 17) ? "evening" : ( (hour > 11) ? "afternoon" : "morning" ); document.write('<img src="' + when + '.png" alt="Good ' + when + '">\n');} This script puts up a png which gives a greeting depending on the time of day. I want instead to put the greeting as text. It's a bit ostentacious as it is.. I would appreciate any pointers. Site is here. Thank you. Similar TutorialsRight i need some help with some code, i have been trying 2 days to get it to work! basically the 3 image locations are in Variables in PHP $piclocation1 $piclocation2 $piclocation3 What i want is when you hover over the div class "breaking-news", i want the div ID "latest-news-image" to change to that specific image background. example the top "breaking-news" class is on hover and the image $piclocation1 should show in "latest-news-image". if the middle "breaking-news" class is on hover the image $piclocation2 should show in "latest-news-image". and so on if you could help me figure out a way around to get this to work i would be ever so greatfull, as i dont know if i got this in the right area as it would contain javascript, php and poss Css! and even if you could point me in the right direction would be helpful! this is the website page i am testing it on if you would like to look at if visually http://www.wolverhampton-wanderers.co.uk/text.php and here is the code: Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="Stylesheet" type="text/css" href="./wolves.css"/> <title>Untitled Document</title> <?php $getnews = "SELECT * FROM `news` ORDER BY `news`.`id` DESC LIMIT 3"; $news = mysql_query($getnews) or die(mysql_error()); $counter = 1; while($row1 = mysql_fetch_array($news)){ if($counter == 1) { $picture1 = $row1['imageID']; $getimage1 = "SELECT * FROM news_images WHERE imageID = $picture1"; $image1 = mysql_query($getimage1) or die(mysql_error()); $pic1 = mysql_fetch_array($image1); $piclocation1 = $pic1['imageFile']; } if($counter == 2) { $picture2 = $row1['imageID']; $getimage2 = "SELECT * FROM news_images WHERE imageID = $picture2"; $image2 = mysql_query($getimage2) or die(mysql_error()); $pic2 = mysql_fetch_array($image2); $piclocation2 = $pic2['imageFile']; } if($counter == 3) { $picture3 = $row1['imageID']; $getimage3 = "SELECT * FROM news_images WHERE imageID = $picture3"; $image3 = mysql_query($getimage3) or die(mysql_error()); $pic3 = mysql_fetch_array($image3); $piclocation3 = $pic3['imageFile']; } $counter = $counter + 1; } ?> </head> <body> <div class="shaddow"><!-- This is the shaddow behind the content --> <div class="content"> <!-- This is the content and main background --> <div class="header"><img src="../images/header.jpg"/></div> <div class="menu"> <div id="nav"> <?php $cat = "SELECT * FROM `top-menu` ORDER BY 'category' ASC"; $category = mysql_query($cat) or die(mysql_error()); $start = 1; while($row = mysql_fetch_array($category)){ $submenu = $row['sub-menu']; if($submenu == '1'){ echo "</li><li><a id='{$row['Active-ID']}' " . "href='{$row['Address']}'>" . "{$row['Text']}</a>"; } elseif($submenu == '2'){ if($start == 1){ echo "<ul>"; } echo "<li><a id='{$row['Active-ID']}' " . "href='{$row['Address']}'>" . "{$row['Text']}</a></li>"; $start = $start + 1; if($submenu !='2'){ echo "</ul></li>"; $start = 1; } } } echo "</ul></li><a class='nav-end'></a>"; ?> </div> </div> <div id="latest-news"> <?php $getnews = "SELECT * FROM `news` ORDER BY `news`.`id` DESC LIMIT 3"; $news = mysql_query($getnews) or die(mysql_error()); $counter = 0; echo "<div id='latest-news-image'></div>" . "<div id='latest-news-header'>Breaking News</div>"; while($row1 = mysql_fetch_array($news)){ echo "<div class='breaking-news'><div class='breaking-news-header'><a href='#'>{$row1['title']}</a></div>" . "<div class='breaking-news-info'>Posted on {$row1['date']}, by {$row1['author']}</div>" . "<div class='breaking-news-desc'>{$row1['desc']}</div>" . "<div class='breaking-news-readmore'><a href='#'>Read More</a></div></div>"; $counter = $counter + 1; } ?> </div> </div> </div> </body> </html> I am creating a photography website and am almost there with coding a very simple image viewer with clickable thumbnails etc. I have used the following script to change the images; Code: <script> function changeImage(filename) { document.mainimage.src = filename; } </script> the main image is like this; Code: <img name="mainimage" src="../Images/wedding-photo-01-bride-getting-ready.JPG" title="bride getting ready"/> And the links/images are like this..... Code: <a href="javascript:changeImage('../Images/wedding-photo-01-bride-getting-ready.JPG')"> <img class="thumbbox" id="mainimage" src="../Images/wedding-photo-01-bride-get-thumb.JPG" alt="wellis photography logo" title="bride getting ready"> </a> This works fine, but I would also like a caption underneath the main image that changes at the same time. Is there a way to do this simply? Perhaps using some variation of the following script? Code: <script type="text/javascript"> document.write(document.getElementById('myimage').title); </script> Also, one other thing - is it possible to add a 'fade' transition to my 'changeimage' function? Thanks in advance Hello, I was wondering if anyone could help me with a personal website I am modifying for a friend. He basically has a list of links such as: Home Blog Pictures Links What I want to do is that whenever you roll over, say, "Blog", an image appears to the right of the links (the image will be a small screenshot of what the blog looks like). When you roll over "Pictures", a different image appears in it's place. I already know how to do this when rolling over images, but not rolling over text. I used document.getElementById and just set the src to the image, but how do I do this when I just have text to roll over? Is it possible/recommended to use the follow JQuery? http://ajax.googleapis.com/ajax/libs.../jquery.min.js Thank you for your time I am new to JavaScript and I am having a difficult time finding what I thought would be easy to find (so please forgive me if this has been posted somewhere else...) I have 4 text strings that when a user runs his/her mouseOver, I'd like to display a corresponding picture in a display area. I thought that would be easy enough. However, it gets a bit complicated for me since I am also using CSS to position the display area. For some reason all I can find out there are examples using HTML tables for display image positioning. I don't want to use tables. I'm not sure if this will make a difference but my style sheet is external. Also, the text does not link/go to another page. I REALLY hope that made sense. Someone please help me! I'm very inexperienced with Javascript, but want to use the onclick event to change an image to text. I'm working on a directory type website and want users to have to click on the image of a telephone in order to reveal the telephone number they are looking for. how do i do this? Also is there a way of tracking how many clicks each person gets? I'd really appreciate any help you guys can give me on this http://www.***.com/5.html i cant get a caption specific to each image to display under the arrows when the image changes. it is especially hard for me because i have to edit the javascript which confuses the **** out of me. it seemed so simple.... thanks for any help ps i cant start an id with a digit? it doesnt seem to cause any problems...why is it stated that this cannot or shouldnot be done? OK right I got a modification from here that someone requested a few weeks ago. It was supposed to replace text in the userlinks. Since I'm in IPB I find it very useful. But here's the thing I try to replace "0 New Messages" to "Inbox[0]" it worked but when I get new PM's it doesn't work like it should. So I rearranged the code but it doesn't work Code: var mb = document.getElementById("userlinks").getElementsByTagName("a"); for(bm = 0;bm < mb.length;bm++){ if(mb[bm].innerHTML=="My Controls"){mb[bm].innerHTML="Preferences"} for(fi=0;fi < mb[bm].innerHTML.length;fi++){ if(fi[mb['bm']].innerHTML==""+fi+" New Messages"){fi[mb[bm]].innerHTML="Inbox "+fi+""} } } ^^ My part there in the code is retarded lol I am trying to learn SVG and I have alot of the basics including javascript manipulation. But I am really stuck on trying to manipulate the actual text itself. Code: <text id="text1" x="300" y="200" font-size="60" font-family="tempus sans itc" stroke="red" stroke-width="2" onmouseover="changeText()"> OMG </text> I am trying to change the text "OMG" to say something else when you hover over it. For example: It says OMG, I want to hover over the text and have it change to WTF. Like you could do with innerHTML. anybody have any experience with SVG that cuold help me? Hi all, Hope you can help with the following. I'm trying to change the contents of DIV2 when I click on DIV1. The following code doesn't work for some reason. I'm using Windows 7 (64-bit), and testing on Firefox 3.6.8 and IE8. Code: <html> <head> <script type="text/javascript" language="javascript"> function test() { document.getElementById("test2").innerHMTL="hello"; } </script> </head> <body> <div id="test1" style="border: 1px solid #ff0000; width: 200px; height: 100px;" onclick="test();">Test Box 1</div> <div id="test2" style="border: 1px solid #ff0000; width: 200px; height: 100px;">Test Box 2</div> </body> </html> Any help appreciated, Cheers Sean Hello, I'm trying to put a site together and this time I'm going for an interactive feel. Code: <p id="status">[Closed]</p> Thats the html of it. What i'm trying to accomplish is when the mouse goes onto the <p>, the [Closed] then turns into Code: <a href="index.php">Open</a> but I can't get this figured. Could someone help me? Thnx! Im new to this forum and was wondering if anyone would mind helping me out. Im attempting to modify some code i found here through google to be used to change a welcome screen to 4 different languages besides english. heres the code <code> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <style type="text/css"> .hide { display:none; } .show { display:inline; } </style> <script type="text/javascript"> if(window.addEventListener){ window.addEventListener('load',showlinks,false); } else { if(window.attachEvent){ window.attachEvent('onload',showlinks); } } function showlinks() { lis=document.getElementById('nav').getElementsByTagName('li'); for(c=0;c<lis.length;c++){ lis[c].onmouseover=function() { this.getElementsByTagName('span')[0].className='hide'; this.getElementsByTagName('span')[1].className='show'; } lis[c].onmouseout=function() { this.getElementsByTagName('span')[0].className='show'; this.getElementsByTagName('span')[1].className='hide'; } } } </script> </head> <body> <ul id="nav"> <li> <span>[Closed]</span> <span class="hide"><a href="http://www.codingforums.com/">codingforums.com</a></span> </li><li> <span>[Closed]</span> <span class="hide"><a href="http://www.google.com/">google.com</a></span> </li><li> <span>[Closed]</span> <span class="hide"><a href="http://www.bbc.co.uk/">bbc.co.uk</a></span> </li><li> <span>[Closed]</span> <span class="hide"><a href="http://w3c.org/">w3c.org</a></span> </li> </ul> </body> </html> </code> As far as i can tell, if i just add the correct number of span id's it should work, or is there a different code i must plug in to get it to switch to the different languages. hi i wants to change one input to texarea when i select one from radio, plz any suggestion how i would do that? my code PHP Code: <input type="text" name="other" value="this need to become textarea" /> <input type="radio" name="inputtext" />Text <input type="radio" name="inputtext" />Textarea so when i click inputtext radio name"other" will become a textrea rather then input type text. thanks for any help. Hi i am trying to change the colour of the text in my menu bar, i know you can do this with css or jquery but i want to try and do it with javascript in an external script sheet. I want to use the onmouseover and onmouseout functions to change the colours, and i want it so their are different colours for each menu item. Can anybody help me? Hi there just wondering if its possible to make a text box in java script and then for that box 2 change colour when the user inputs something. For example if they enter 3 it will turn green but if they enter anything else then it will turn red. Thanks here is my problem i need to set the color of a text here is what i need to change Code: <div style="position:absolute; left:10px; top:100px; width:250px; text-align:center;"> <font color="lightgreen" size="6"><b>* Mileage *</b></font><b> <font color="black" size="6"><div id="bullet4">Not Specified</div></font><br></b> <font color="lightgreen" size="6"><b>* Gearbox *</b></font><b> <font color="black" size="6"><div id="bullet5">Not Specified</div></font><br></b> <font color="lightgreen" size="6"><b>* Engine size *</b></font><b> <font color="black" size="6"><div id="bullet6">Not Specified</div></font><br></b> <font color="lightgreen" size="6"><b>* Body style *</b></font><b> <font color="black" size="6"><div id="bullet7">Not Specified</div></font><br></b> </div> now i need to set the color from a text file server side so far i can set the contents of the div serverside but the customer needs to be able to change the color of the innerhtml . now i would like to store the color in a text file color.txt i can make the code to change the txt file myself inside the color.txt would be "lightgreen" or other color how would i go about this. so in basic terms i need to set the color of the text from a color.txt file sat next to the index.html Is there a way to change the text from OK to CLOSE on an alert box ?
hello, I have a problem changing the value of multiple text boxes, My page contain one text box named "price" and i need to set the value of this box to all other text boxes in the page which they attribute is <input type="text" value="" name="product[xxxx]" id="product"/> xxxx = random number the page may contain only one text box id=product or more i have tried the following code but it only works with multiple text boxes and doesn't work if the page have one text box Code: var price = document.getElementById('price').value; var allElements = document.form1.product; var len=allElements.length; if(allElements.length){ for (i = 0; i < len; i++){ allElements[i].value = price; } I'm not a javascript expert so i don't know if this code is the right way to accomplish this. Thank you very much for your help I'm writing a calculator script that will need user input (how much they pay on internet, phone or cable bill) and then multiply those numbers by a known rate and then show the customer the new number. I have the math setup (working right now), and the script works to spit out the answers in an alert. Instead of the alert (which is the only thing I can do correctly at this point), I need the script to give the answers for each bill and then a total answer at the bottom. The script is here, it's all in the index file. http://gotsmith.com/calculator/ Thanks. Hi Guys, I am looking for a script to change text on a page based on the time of day. From 9am - 5pm weekdays I would like the page to display 'Open', and outside of that window to display 'Closed'. I am using HTML & PHP. Any help would be greatly appreciated. Thanks, Matt |