JavaScript - Please Help Me To Make Html Page Load Random Bg Image On Refresh
Hi. I am new here.
I wanted help for a JavaScript code. You might think I'm lazy for not writing it myself, but the truth is I am not a JavaScript coder. I just have a really simple website and I am trying to do something for which I know JS is required but I don't know how to do it. I've also searched around but couldn't find the appropriate code. What I want to do is to make an html page load a different background image every time it refreshes. I will have a list of background images and I want to be able to add in this list, without having to change anything else in the codes after I do this (I think this is made by making an array of images and by putting .length somewhere in the codes, but I don't know exactly how I should do this). I already know how to do an external file (.js) and link to it from my .html page. Now I want the code to put in the .js file, and the code to put in the <body> of my .html file. Please help me Thanks Similar TutorialsHello, I am using the following script on my site RCENO .com in a easyadsense plugin, it is working well, because it is adding the elements after the posts on the page, but instead of rotating (This causes a problem when a Video is playing, and it rotates out in the middle of it) I would like for it to be Random when the posts load or refreshed....This is a Wordpress CMS site that provides News and Event Information to the local area, I am using this to display Holiday Greetings from area merchants in the form of Videos....... Thank You For Your assistance on This <script type="text/javascript"> if (document.all || document.getElementById){ //if IE4 or NS6+ document.write('<style type="text/css">\n') document.write('.dyncontent{display: none; width: 340px; height: 230px;}\n') document.write('</style>') } var curcontentindex=0 var messages=new Array() function getElementByClass(classname){ var inc=0 var alltags=document.all? document.all : document.getElementsByTagName("*") for (i=0; i<alltags.length; i++){ if (alltags[i].className==classname) messages[inc++]=alltags[i] } } function rotatecontent(){ //get current message index (to show it): curcontentindex=(curcontentindex<messages.length-1)? curcontentindex+1 : 0 //get previous message index (to hide it): prevcontentindex=(curcontentindex==0)? messages.length-1 : curcontentindex-1 messages[prevcontentindex].style.display="none" //hide previous message messages[curcontentindex].style.display="block" //show current message } window.onload=function(){ if (document.all || document.getElementById){ getElementByClass("dyncontent") setInterval("rotatecontent()", 75000) } } </script> Season Greetings: <div class="dyncontent" style="display: block">[flv:/files/videos/HolidayGreetings/FamilyVideoGreetings.flv 340 230]</div> <div class="dyncontent">To Add Your Holiday Greetings, Contact Us at Roy@rceno.com or Call (336) 398-6003</div> <div class="dyncontent">Happy Holidays</div> That's right, I want to load a random html file from a list into a another div. Does anyone knows any example, please? It would be very helpful. Thanks Hi I have some Javascript on my website http://www.restoreanddesign.co.uk The top bar has 4 images on a random cycle on load up/ refresh. Im trying to validate the xhtml, but it is coming up with errors. I dont understand javascript enough to be able to fix this. Anyone know what needs to be done to validate this javascript. i have bolded/coloured the lines i think is causing the problems -------------------------------------------------------------------- Code: <script type="text/javascript" language="JavaScript"> // JavaScript Document var imagenumber = 4 ; var randomnumber = Math.random() ; var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ; images = new Array images[1] = "images/newtopbar.jpg" images[2] = "images/newtopbar2.jpg" images[3] = "images/newtopbar3.jpg" images[4] = "images/newtopbar4.jpg" var image = images[rand1] function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } </script> How do I make a swf pop up, on load, on a home page? Similar to the lightbox technique, I want an swf file to pop up on the home page when it first loads. I have looked into a similar type of script called "milkbox" but have had no luck. Any Advice would be greatly appreciated as I need this working within a day. Thank you so much and sorry if this should be posted in the Flash Section. On this website... http://livedemo00.template-help.com/...21/index.html# When you click on the Navigation Bar the website pages load inside that page? How exactly would i go around doing this? Thankyou I have a single webpage that contains information on all 50 U.S. states. There are 50 links at the top to jump down to the state you want, and at the bottom of the information for each state a Back to Top link. I'm making the Back to Top link into something more complex, and it will require three or four lines of code. So that I don't have to repeat the code 50 times, and create a burden when I need to edit it, I want to place it in a .js file and call it x. Then below the information for each state I'll simply have: Code: <script language="JavaScript">document.write(x)</script> Does calling code from a .js file 50 times slow down the page load? Which method would load faster? Or is the difference negligible? Thank you, Peter How do you make an image begin to load after a certain amount of time? e.g 3 seconds.
I have a php file lets say file1.php, that printing a variable, its dynamic numbers output that already always increasing, like private message numbers that coming or others : PHP Code: <?php echo $variable ?> i want to put that variable output, in another files page title, lets say file2.php or file3.html, in the front of the another files page titles, and auto refresh every x seconds, maybe like this : Quote: (1) - another text in the page title after x seconds, get a private message Quote: (2) - another text in the page title after another x seconds, get another private message Quote: (3) - another text in the page title or its ok if just like this, only the variable, without the another text in the page title Quote: (1) please share your knowledge to make it, maybe using javascript, jquery or others Here are the coding.. Code: <jsp:useBean id="chequeStopBean" scope="session" class="my.com.infopro.ibank.ui.bean.ChequeStopBean"/> <jsp:useBean id="labelBean" scope="session" class="my.com.infopro.ibank.ui.bean.LabelBean"/> <jsp:useBean id="lang" scope="session" class="my.com.infopro.ibank.ui.bean.LanguageBean" /> <%@ page language="java" import = "java.util.*" errorPage="" %> <%@ page import="my.com.infopro.ibank.dto.ChequeDTO"%> <% request.getSession(true); String contextPath = request.getContextPath(); chequeStopBean.queryAccList(); //RequestDispatcher dispatcher = null; %> <html> <head> <title><%=labelBean.getLabel("STOP_CHEQUE")%></title> <meta HTTP-EQUIV="Pragma" content="no-cache"> <meta HTTP-EQUIV="Expires" content="-1"> <jsp:include page="/ScriptHeader.jsp"/> <script language="javascript"> function validateAndSubmit() { var msg1 = "<%=labelBean.getLabel("MSG_REQUIRED_FIELD")%>"; var msg2 = "<%=labelBean.getLabel("MSG_CANNOT_CONTAIN_CHARACTER")%>"; var msg3 = "<%=labelBean.getLabel("MSG_IN_THE_FIELD")%>"; var msg4 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER")%>"; var msg5 = "<%=labelBean.getLabel("WITH")%>"; var msg6 = "<%=labelBean.getLabel("TO")%>"; var msg7 = "<%=labelBean.getLabel("MSG_CHARACTER")%>"; var msg8 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_VALID_NUMBER")%>"; var msg9 = "<%=labelBean.getLabel("MSG_REQUIRED_FIELD")%>"; var msg10 = "<%=labelBean.getLabel("MSG_WITH_EXACTLY")%>"; var msg11 = "<%=labelBean.getLabel("MSG_WITH_VALID_DATE")%>"; var msg12 = "<%=labelBean.getLabel("MSG_EXAMPLE_DATE")%>"; var msgNum11 = "<%=labelBean.getLabel("MSG_WITH_A_MINIMUM_VALUE_OF")%>"; var msgNum12 = "<%=labelBean.getLabel("MSG_WITH_A_MAX_VALUE_OF")%>"; var msgNum13 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_ROUND_INETEGER")%>"; var msgNum14 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_AT_MOST")%>"; var msgNum15 = "<%=labelBean.getLabel("MSG_DECIMAL_PLACES")%>"; var msgEnter = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_VALID")%>"; var errorMsg = "<%=labelBean.getLabel("MSG_LOWECASE_ALPHABET_ALLOWED")%>" var radioButtons = document.getElementsByName("radio"); for (var x = 0; x < radioButtons.length; x ++) { if (radioButtons[x].checked) { if(radioButtons[x].value=="1") { if (! validateTextEntry(form.chqNum, "<%=labelBean.getLabel("CHQNUM")%>" + " ", true,11,11, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg10) ) return false; if (! validateAlphabet(form.chqNum, "" + " ",1, msg2,"" )) return false; } else if(radioButtons[x].value=="2") { if (! validateTextEntry(form.chqNumFrom, "<%=labelBean.getLabel("CHQNUMFROM")%>" + " ", true,11,11, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg10) ) return false; if (! validateTextEntry(form.chqNumTo, "<%=labelBean.getLabel("CHQNUMTO")%>" + " ", true,11,11, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg10) ) return false; if (! validateAlphabet(form.chqNumFrom, "" + " ",1, msg2,"" )) return false; if (! validateAlphabet(form.chqNumTo, "" + " ",1, msg2,"" )) return false; if(form.chqNumFrom.value == form.chqNumTo.value){ alert("<%=labelBean.getLabel("MSG_CANNOT_SAME")%>"); return false; } } } } return true; } function show(id) { if (document.getElementById(id).style.display == 'none') { document.getElementById(id).style.display = 'block'; } } //--> <!-- function hide(id) { document.getElementById(id).style.display = 'none'; } </script> </head> <body onload="show('single')"> <form name="form" method="POST" action="<%=contextPath%>/ChequeStopServlet?tranx=confirm" dir="<%=lang.getDir()%>" > <table width="500" align="center"> <tr> <td align="left" colspan="3"> </td> </tr> <tr> <td align="left" colspan="3" class="mainHeader"><%=labelBean.getLabel("STOP_CHEQUE")%></td> </tr> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3" class="subHeader"><%=labelBean.getLabel("CHQ_DETAIL") %></td> </tr> <tr> <td colspan="3"><div align="center"> <p class="statusError"> <%if(request.getParameter("error") != null) out.println(labelBean.getLabel(request.getParameter("error"))); else out.println("");%> </p> </div></td> </tr> </table><br /> <table width="500" align="center"> <tr> <td class="lbl"><span class="requiredFieldIndicator">* </span><%=labelBean.getLabel("ACC_NUMBER")%></td> <td width="10" class="lbl">:</td> <td width="305" align="left"> <select size="1" name="accNum"> <% for (Iterator iter = chequeStopBean.getAccList().iterator(); iter.hasNext();) { ChequeDTO chqDto = (ChequeDTO)iter.next(); %> <option value="<%=chqDto.getAccNum()%>"><%=chqDto.getAccNum()%></option> <% } %> </select> </td> </tr> <tr> <td align="right"> <input type="radio" class="radioStyle" name="radio" value="1" onfocus="show('single');hide('multiple');hide('multiple1');return true;" checked="checked" > <%=labelBean.getLabel("STOP_SINGLE")%> </td> <td> </td> <td> <input type="radio" class="radioStyle" name="radio" value="2" onfocus="hide('single');show('multiple');show('multiple1');return true;"> <%=labelBean.getLabel("STOP_MULTIPLE")%> </td> </tr> <tr id="single"> <td class="lbl"><span class="requiredFieldIndicator">* </span><%=labelBean.getLabel("CHEQUE_NUMBER")%></td> <td class="lbl"width="10">:</td> <td colspan="2" align="left"> <input name="chqNum" type="text" size="15"> </td></tr> <tr id="multiple" style="display: 'none'"> <td class="lbl"><span class="requiredFieldIndicator">* </span><%=labelBean.getLabel("FROM_CHEQUE_NUMBER")%></td> <td class="lbl"width="10">:</td> <td colspan="2" align="left"> <input name="chqNumFrom" type="text" size="15"> </td></tr> <tr id="multiple1" style="display: 'none'"> <td class="lbl"><span class="requiredFieldIndicator">* </span><%=labelBean.getLabel("TO_CHEQUE_NUMBER")%></td> <td class="lbl"width="10">:</td> <td colspan="2" align="left"> <input name="chqNumTo" type="text" size="15"> </td></tr> <tr> <td class="lbl"><span class="requiredFieldIndicator">* </span><%=labelBean.getLabel("REASON")%></td> <td class="lbl" width="10" >:</td> <td colspan="2"> <select name="reason"> <option value="Lost"><%=labelBean.getLabel("LOST")%></option> <option value="Stolen"><%=labelBean.getLabel("STOLEN")%></option> <option value="Payment Cancellation"><%=labelBean.getLabel("PAYMENT_CANCELLATION")%></option> <option value="Others"><%=labelBean.getLabel("OTHERS")%></option> </select> </td> </tr> <br/> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3" align="center"> <input class="button" type="submit" value="Next" onClick="return validateAndSubmit();" > </td> </tr> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3" align="left" class="footer"><%=labelBean.getLabel("NOTE")%> </td> </tr> <tr><td colspan="3" class="footer"> <ul> <li><%=labelBean.getLabel("THE_ASTERISK")%></li> </ul> </td> </tr> </table> <jsp:include page="/Footer.jsp" /> </form> </body> </html> This is error for the first page.. This is picture that which i wan.. Thanks! Hello! I have been designing a schedule website which will be displayed on several computers throughout the building, I would like to be able to edit the JS during the day but I do not want to be going all through the building refreshing every computer to make sure it has the latest JS version. I also do not want use the meta HTML tag to refresh because that is too noticeable with the images reloading. Basically I would like to only refresh the JS file. I found this link, but it has a button which defeats the purpose. Any way of doing this without the button? FYI, I have the javascript setTimeout("driver()",1000); already so that the clock stays up to date. Not sure if that will make things easier or more complicated... EDIT: not sure why the ICODE tags are not working EDIT 2: Forgot the website! http://www.philnicholas.com/2009/05/...ing-your-page/ Hi all! My first post here, searched around for a good website to get some assistance and chose CodingForums.com! I'm a graphic designer, and trying my best at web design too although it's not my profession so I'm still beginner level in a sense I guess. Anyway, my dilemma at the moment is that I have produced a site where the client would like the logo colour/image to change on refresh which I have achieved by scouring the net for codes and altering them. Now, the client wants the shapes behind the sub-headings to match the current logo colour/image on refresh as well. This would mean if the logo changed to the blue logo, I'd need all the sub-headings to be blue, and vice versa for another 3 colours. I'm struggling to understand how I can achieve this. At the moment, I have a javascript inside the code of the index page allowing logo image change on refresh but need the sub-headings to change in sync too. Can anyone help me out here? Any help is greatly appreciated. Thanks all! WxMx It must be a simple thing... I am trying to change an image source on page load depending on the contents of a cookie: Code: function goVisited(cookiename,img_name,img_src) { var visited = readCookie(cookiename); if (visited == "1"){ //alert("visited!"); document[img_name].src=img_src; }} <img onload="goVisited('main1','Introduction','img/Yellow.gif');" name="Introduction" border="0" src="img/Green.gif" width="250" height="18"> I need the page to check the cookie "main1" and if its value is 1, then change the image src from Green.gif to Yellow.gif. It almost works, but I get a stack overflow. Hey all, I'm trying to make it so that when a user clicks on a radio button, the image that is related to the radio button is displayed next to it (without reloading the page). At the moment all it shows is the image related to the currently saved option, which I'd like to keep on page load. Is this possible? If so, I'd appriciate any help. Here is my code for the radio buttons. Thanks. Code: <tr valign="top"> <td id="community-legal-services-logo-selection"> <p><label><?php _e('<strong class="table_tags">Display the following Community Legal Services logo:</strong>'); ?></p> <p><label for="cls-mono"> <input class="" id="cls-mono" name="cls_logo" type="radio" value="cls_mono" <?php if($general_options['cls_logo'] === 'cls_mono'){ echo 'checked="checked"'; } ?> /> <?php _e('Mono'); ?></label> </p> <p><label for="cls-color"> <input class="" id="cls-color" name="cls_logo" type="radio" value="cls_color" <?php if($general_options['cls_logo'] === 'cls_color'){ echo 'checked="checked"'; } ?> /> <?php _e('Colour'); ?></label> </p> <p><label for="cls-none"> <input class="" id="cls-none" name="cls_logo" type="radio" value="cls_none" <?php if($general_options['cls_logo'] === 'cls_none'){ echo 'checked="checked"'; } ?> /> <?php _e('None'); ?></label> </p> <p> <label><?php _e('<span class="table_tags">Link to the Community Legal Services website<span>'); ?></label> </p> <p> <input class="large_input_box" id="cls-link" name="cls_link" type="text" value="<?php echo $general_options['cls_link']; ?>" /></label> </p> </td> <?php if($general_options['cls_logo'] && $general_options['cls_logo'] !== 'cls_none'){ ?> <td> <img id="community-legal-services-logo-preview" class="image-preview" src="<?php echo $general_options['cls_logo_path']?>" /> </td> <?php } ?> </tr> Hi all Is there a way to get the image(s) to load into the table after the page has loaded instead of the way I have it now? I have 4 tabs, but I would like the imgs in tabs 2,3,4 to load after page load. Example of how the tabs look. Code: <div class="tabbertab"> <h2>Australia_____</h2> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFCC"> <caption class="highlight_Red">澳洲 Australia </caption> <tr> <td><a href="pages/promotion.html#aus_ACE" rel="nofollow" target="_blank"><img src="pages/images/Pics/AUS/ace.jpg" alt="ACE / ATTC" width="110" height="69" border="0" align="left" class="ozimg_L"/> ...a few more images etc the other tabs look the same. LT Hi-- I have found a neat trick to refresh an iframe in an html page, but I just need one little twist to make it work just right. I would like to make the iframe content refresh just once, not matter how many times the link is clicked... Right now, I have this in the head: Quote: <script type="text/javascript"> function refreshIframe(el) { var f = document.getElementById(el) var rsrc = f.src f.src="about:blank" f.src=rsrc } </script> And this is the link which, when clicked, refreshes the iframe every time it is clicked: Quote: <a href="#page_7c" onclick="refreshIframe('test'); return false"> "test" is the id of the iframe. I am sure how to do this is really simple, but it escapes me... Many thanks! This script displays a link to a registration/login form that loads in a light box for Joomla. I've been goin nuts trying to figure out how to get this to load on page load with a delay. Anyone know how to get this done? PHP Code: <?php JHTML::_('behavior.mootools'); $document = JFactory::getDocument(); $document->addStyleSheet(JURI::base() . 'media/system/css/modal.css'); $document->addScript(JURI::base() . 'media/system/js/modal.js'); $document->addScriptDeclaration("window.addEvent('domready', function() {SqueezeBox.initialize({});});"); $user = & JFactory::getUser(); $uri = JFactory::getURI(); $url = $uri->toString(); $return = base64_encode($url); ?> <div id="lbframeid" style="position:absolute;top:1px;left:1px;height:0px;width:0px;overflow:hidden"> <a href="http://www.wowjoomla.com/"><h1>Joomla Login LightBox powered by WowJoomla.com</h1> </a> </div> <?php if ($user->get('guest')) :?> <a href="<?php echo JRoute::_('index.php?option=com_loginbox')?>" onclick="SqueezeBox.fromElement(this); return false;" rel="{handler: 'iframe', size: {x: 660, y: 500}}"><?php echo JText::_('SIGNUP_LOGIN')?></a> <?php else: ?> <?php echo JText::sprintf( 'HINAME', $user->get('name') ); ?> <br> <a href="javascript:void(0);" onclick="LB_onLogout(); return false;"><?php echo JText::_('LOGOUT')?></a> <?php endif; ?> <script type="text/javascript"> function LB_onLogout() { var form = new Element('form'); form.setProperty('method', 'POST'); form.setProperty('target', '_self'); form.setProperty('action', 'index.php'); var input = new Element('input'); input.setProperty('type', 'hidden'); input.setProperty('name', 'option'); input.setProperty('value', 'com_user'); form.appendChild(input); var input = new Element('input'); input.setProperty('type', 'hidden'); input.setProperty('name', 'task'); input.setProperty('value', 'logout'); form.appendChild(input); var input = new Element('input'); input.setProperty('type', 'hidden'); input.setProperty('name', 'return'); input.setProperty('value', '<?php echo $return; ?>'); form.appendChild(input); $E('body').appendChild(form); form.submit(); } </script> I am trying to make the following fill the value box when the page loads as opposed to pressing the button. I cant seem to do it. Any ideas?? PHP Code: <script> var keylist="abcdefghijklmnopqrstuvwxyz123456789" var temp='' function generatepass(plength){ temp='' for (i=0;i<plength;i++) temp+=keylist.charAt(Math.floor(Math.random()*keylist.length)) return temp } function populateform(enterlength){ document.pgenerate.output.value=generatepass(enterlength) } </script> <form name="pgenerate"> <input type="text" size=18 name="output"> <input type="button" value="Generate Password" onClick="populateform(this.form.thelength.value)"><br /> <b>Password Length:</b> <input type="text" name="thelength" size=3 value="7"> </form> How do I make my Script load faster? Is there Code that will make my Script load faster, (so that it won't take so long to view) If so, can someone show me how to incorporate it into my Example Script? With appreciation |