Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    change java to load random on refresh

    Sorry I am very very new to this but we are trying to get a page to load random content on a refresh. I have the code to do a slideshow with text but would like it to load random when you refresh or hit the page again. Again excuse my ignorance I have no experience in this. Hoping I can just change something in the code below to make it random. Thanks in Advance!

    here is the code i have
    Code:
    // Begin Sequence Banner
    (function($){
    	$.fn.scSequenceBanner = function(options){
    		var defaults = {
    			slideOnClass : "scSBon",
    			slidePausePos : "center",
    			slideWidth : 500,
    			showNumbers : false,
    			slideAuto : true,
    			slideTimer : 7,
    			showNumbersX : 100,
    			showNumbersY : 100
    		};
    		var settings = $.extend({},defaults,options);
    		return this.each(function(){
    			var mainObj = $(this);
    			var subMainObj = mainObj.children("div");
    			var slideObjs = mainObj.children("div").children("div");
    			var slideNumber = subMainObj.children("div").length;
    			var currNum = 0, pauseBtn; 
    			
    			// set main containers width
    			subMainObj.css('width',(settings.slideWidth)+"px");
    			
    			// if slideAuto is True start interval
    			function startInterval(){
    				var slideTime = settings.slideTimer*1000;
    				scSBInterval = setInterval(processAuto,slideTime);
    			}
    			
    			// scrolling function
    			function processBtn(_btnnum){
    				var numberBtns = numberContainer.children("a");
    				numberBtns.removeClass(settings.slideOnClass);
    				numberBtns.eq(_btnnum).addClass(settings.slideOnClass);
    				currNum=_btnnum; 
    			}
    			
    			// auto scroll process
    			function processAuto(){
    				(currNum==(slideNumber-1)) ? currNum = 0 : currNum += 1;
    				(settings.showNumbers) ? processBtn(currNum) : ''; 
    				processTransition(currNum); 
    			}
    	
    			// transition function
    			function processTransition(_btnnum){
    				subMainObj.children().eq(_btnnum).animate({opacity:1},300).css('z-index',1);
    				subMainObj.children().not(slideObjs.eq(_btnnum)).animate({opacity:0},300).css('z-index',0);				
    			}
    			
    			// show number buttons
    			function showNumbers(){
    				numberContainer = $(document.createElement("div")).addClass("scSequenceButtons").css("bottom",settings.showNumbersY).css("right",settings.showNumbersX);
    				slideObjs.each(function(i){
    					numberContainer.append($(document.createElement("a")).click(function(e){processBtn(i); processTransition(i); (settings.slideAuto) ? clearInterval(scSBInterval) : ''; e.preventDefault();}).addClass("scSButton").text(i+1));
    				});
    				mainObj.append(numberContainer);
    				numberContainer.children("a").eq(0).addClass(settings.slideOnClass);
    			}
    			
    			// pause button functionality
    			function showPause(){
    				pauseBtn.animate({bottom:0},400);
    			}
    			function hidePause(){
    				pauseBtn.animate({bottom:-pauseBtn.height()},400);
    			}
    			$.fn.opacity = function(_value) {
    				return $(this).css('opacity',_value);
    			};
    			// feature initialization
    			$.fn.initialize = function(){
    				slideObjs.each(function(){
    					slide = $(this);
    					slide.width(settings.slideWidth).height(mainObj.height());
    					slide.not(slideObjs.eq(0)).opacity(0).css('z-index',0);
    					slideObjs.eq(0).opacity(1).css('z-index',1)
    				});
    				(settings.showNumbers) ? showNumbers() : '';
    				if(settings.slideAuto){
    					mainObj.hover(function(){clearInterval(scSBInterval); showPause();},function(){startInterval(); hidePause();});
    					startInterval();
    					pauseBtn = $(document.createElement("div")).addClass("scSequencePause");
    					mainObj.append(pauseBtn);
    					switch(settings.slidePausePos){
    						case "right":
    						pauseBtn.css({bottom:-pauseBtn.height(),left:(mainObj.width()-pauseBtn.width())});
    						break;
    						case "left":
    						pauseBtn.css({bottom:-pauseBtn.height(),left:0});
    						break; 
    						case "center":
    						pauseBtn.css({bottom:-pauseBtn.height(),left:(mainObj.width()/2-pauseBtn.width()/2)});
    						break;
    					}
    				}
    			}
    		});
    	}
    })(jQuery);
    // End Sequence Banner
    
    jQuery(document).ready(function() {
    		//Sequence Banner
    		if($('.scSequenceBanner').length > 0) {
    			var scSB = $('.scSequenceBanner').scSequenceBanner({slideWidth:985,showNumbersX:15,showNumbersY:15,
    					showNumbers:false
    					,slideTimer:7
    					,slideAuto:true
    			}); 
    			scSB.initialize();
    		}
    });

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,683
    Thanks
    25
    Thanked 656 Times in 655 Posts
    Java is a programming language, so is javascript. They are different. No not mistake one for the other.

    JS works AFTER the page renders so it is a bad choice for this. Look into a server side language like PHP or ASP to do this.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Quote Originally Posted by sunfighter View Post
    JS works AFTER the page renders so it is a bad choice for this. Look into a server side language like PHP or ASP to do this.
    Actually, with most browsers supporting the ability to manipulate the DOM after the page loads, JS would be just fine for randomly selecting content with each page load.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,683
    Thanks
    25
    Thanked 656 Times in 655 Posts
    I do agree with you Wolf, but it's not my first choice since it's kind a like putting the horse behind the cart. Pushing instead of pulling.
    Just seems like a waste of time and bandwidth to load a page and then reload another random page. If this is done server side the random page is selected and a single page is send down the pipe saving paying for excess server use and the flash of putting the wrong page up and then changing it.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I could be splitting hairs, here.. or I could completely misunderstand the OP's request.. but the way I interpreted the question was not "random pages", rather "random content of a single page".. sort of like random quotes of the day appearing in a small div or span in the corner of the homepage.

    OP, could you please clarify your request?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #6
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're exactly right to load random content on our home page....not to load random pages Thanks for the replies and again excuse my ignorance.

    Quote Originally Posted by WolfShade View Post
    I could be splitting hairs, here.. or I could completely misunderstand the OP's request.. but the way I interpreted the question was not "random pages", rather "random content of a single page".. sort of like random quotes of the day appearing in a small div or span in the corner of the homepage.

    OP, could you please clarify your request?

  • #7
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Just out of curiosity, are you using any server-side scripting? ASP, JSP, PHP, ColdFusion, etc. Even if not, you could still use AJaX to "GET" a page, in the background, and dynamically change the content of a DIV as soon as the DOM is ready.

    You could set up (for example, using an arbitrary number) ten .htm pages, each with different content, and without a doctype declaration, or HEAD/BODY tags; just content/formatting. Name them "page0.htm" through "page9.htm".

    On the page where you want to display the random content, use JavaScript to choose a random number between 0 and 9. Set that to a global variable.

    Use AJaX to get "page" + varX + ".htm", parse the content and display within a DIV.

    The code that you provided in your original post is (IMHO) complex for such a simple task. I don't have a lot of time, right now, to throw into it; but I could probably give you some URLs to look up and reference while you're building it.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #8
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wolfshade,

    We are not using a server for scripting. Basically we have an network solutions site that you are able to use a template or use html,js....etc. The code I entered the first time may have not been a good example of what I am trying to do. Here is something the network solutions site is saying would work. I have tried it and I cannot get them to do the random function

    I placed this in the design section of our webpage. Notice the style display is set to none. I cant get them to all show up at the same time but not do a random content on refresh. Thanks again for your help I really appreciate it! I see your in St.Louis I am in Springfield Again my knowledge is very limited on this so thanks for your help

    <h1>Random Div</h1>

    <!--News Section 1-->
    <div id="featured_section1" style="display:none">
    <img src="news_image1.gif" alt="news" />
    <p><strong>Interesting News 1</strong></p>

    Random Div 1 - You can put your text, images, links or videos in this box.
    <br />
    </div>

    <!--News Section 2-->
    <div id="featured_section2" style="display:none">
    <img src="news_image2.gif" alt="news" />
    <p><strong>Interesting News 2</strong></p>

    Random Div 2 - You can put your text, images, links or videos in this box.
    <br />
    </div>

    <!--News Section 3-->
    <div id="featured_section3" style="display:none">
    <img src="news_image3.gif" alt="news" />
    <p><strong>Interesting News >/strong></p>

    Random Div 3 - You can put your text, images, links or videos in this box.
    <br />
    </div>

    Here is the script I am using in the Head of the webpage.
    Notice it says block on the display.

    <script type="text/javascript">

    function random_div() {
    var random_number = "";
    var max = 3; // this is the number of random content boxes you want to rotate
    random_number += Math.floor(Math.random()*max+1);
    showdiv = "featured_section" + random_number;
    document.getElementById(showdiv).style.display = 'block';
    }
    </script>

  • #9
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Sorry for delaying in response. I can give it some thought, this weekend. Don't want the boss giving me the "hairy eyeball".
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #10
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Sorry.. busy weekend.. I'll try to find some time, later this week.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •