JavaScript - If Statement Redirect Based On Scorm Score
I am having some trouble trying to adapt some code to create a better user experience. I use a Rapid E-learning Dev Tool called Udutu. Its limited in some functionality but I'm hoping to find a workaround.
As with a lot of e-learning, user activity including their assessment score is passed to the LMS via a Scorm connection. I need to get that score and then based on the percentage (i.e <= 79) re-direct the user automatically to a page. To get the score within Udutu is as follows: Code: <p>Your score is: <span id=theScore></span> <script>try{var theScoreEl = document.getElementById('theScore');theScoreEl.innerHTML= Math.round(UDUTU_API.generateScore());}catch(ex){}</script> % </p> This bit works fine but now I need to include a if statement to look at the value that it produces and redirect the user accordingly. I've tried to do this but I keep breaking the above code. Any help would really be appreciated Similar TutorialsHi to every one. I'w created a mini javascript game for my site where you click on red button as fastest as you can for 10 seonds to achieve as best as you can click numbers per second. And the end score is a variable which I send to a function which reads the array that contains ten best scores and write your score in same array if it's among 10 best. Now I want to make somehow to save that array on server so I could read it on page load to show a high score list, but I'm having trouble to write that array in any kind of data on server that I could read it again from same data. I would be very grateful if someone can help me! Can anyone help me out with a script that can redirect based on IP address? I want all of my computers on my LAN, 192.168.1.1-255 to be redirected to a specific page. IE When I type in test.homeip.com it goes to my web server and reads the index.html file. If the IP is in the 192.168.1.0 range it will redirect to 192.168.1.10:80 and if its any other IP it will send it to 192.168.1.11:80 Thanks! I have a page with a Geo IP redirect that's supposed to redirect users from London to URL#1 and the rest to URL#2. It's an external geo ip lookup service. First comes the IP lookup: Code: <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"> /* GeoIP Deny Access by City and Redirect Javascript 1.0 http://wiki.category5.tv/MaxMind_GeoIP_API API (c) MaxMind - www.maxmind.com - used with permission "GeoIP Deny Access by City" script by Robbie Ferguson, www.Category5.TV You are free to use and share this script, however this notice must remain intact. */ </script> And then, and here's the problem I think, is the redirects inside an if/else: Code: <script type="text/javascript"> var city=new Array("London, H9") var redirect="http://www.URL1.com" var redirect2="http://www.URL2.com" /* do not edit past this line */ Array.prototype.inArray = function(q) { for(i in this) { if(this[i].toUpperCase() === q) return true; } } var myCity=geoip_city().toUpperCase() var myRegion=geoip_region().toUpperCase() if(city.inArray(myCity+", "+myRegion)) { window.location = redirect; } else { window.location = redirect2; } The redirect works if you are indeed from London. So if the if-statement is true, "window.location = redirect" works, but if the statement is not true, "window.location = redirect2" doesn't seem to be called. Help would be extremely appreciated Hi guys. I am kind of new to javascript, and was hoping that someone here could help out on a problem I have been having. What I am trying to do is to make a page which will redirect to three diffrent sites, based on date. I want it to change to diffrent sites during the time before summer to summer, the time before xmas till xmas and from before easter till easter. A bit more spesific this would be: From 29. march --> 22. july (summer) From 22. august --> 24. december (xmas) From 3. january --> 22. march (easter) Could you help me out? I have tried lots of diffrent ways to do this with javascripts if...else statements, but I havent yet found a way to make it work properly. Really thankful for answers! Hello all. I have created a 2 frame site where I want the top frame (header) to redirect the other frame (main) to a different page depending on the date, time, and second. For example, on 12 FEB at 07:00:00, I would like the header frame to redirect the main frames page to EmmasBday.html; in which I would be alerted of my little sisters Birthday. This is for personal use and isn't going to be hosted online so I will just use JavaScript, it's basically a simple system to remind me of crucial events at certain times and dates so I don't forget them. The same events will apply every year, so there is no need to programme in specific years although having the option could prove useful. I am aware of other alternatives to achieve this, but would very much like to work with JavaScript; as I can expand it. As I state, this is for personal use and therefore won't be hosting it; I will use JavaScript throughout and cannot use anything else like PHP, Perl, etc. I am aware JavaScript takes the time & date from the computer hosting it (unlike PHP), which is fine. So, for example; at 14:30:00 I will be informed to get dinner; and at 15:00:45 I'll be informed to study. The knowledge you guys have presented so far is phenomenal, and I couldn't think of anybody better to ask for assistance. Anyway, I hope you can resolve my problem and I'm looking forward to a response! Thanks for your concern, you brain Gods you! AHa. Hello, Im looking for a script where i can have people come to my websites index page, watch a short video and learn about what my site is about, then click a button called "always skip to "my website here" " so once they click that button, they will always be directed to my main website when they return. I belive it will need to be done with cookies aswell? Thanks Chris, i need to disable a button if a table cell has a certain value inside of it. Code: if (document.getElementById('ba' + roid.value + 'r' + roid2.value + 'c1').innerHTML = " ") { document.getElementsByName('open')[0].disabled=true; } else { document.getElementsByName('open')[0].disabled=false; } That is what i have got. The problem is that the button is constantly disabled no matter what the value and also when it executes it gives that cell the value of . i really dont know what is going on. any help apreciated Hi, Please i am not getting clear understanding of a javascript code to redirect user to a different web page based on the day of the week. Please i have search for many script and not getting clear understanding from their code.I have also try several code myself but nothing good has come from it. Please can someone help me and write a descriptive code for me to understand better.I really plead you and your to help me...but i belief the Lord God will bless you for your time helping me. looking forward to here from you. Thank you. Clement Osei This is what I tried but alas, it does not work por que no? This is located on my main index file which if the result of z is greater than 1, I would have the user stay at this page as opposed to redirecting to the portrait design. I have optimized the website for mobile use so there is a reason of having two different pages, the wide screen has extra tools / other stuff that isn't shown on the portrait not because of size/responsive design but becasue I want it to be this way. Anyway... "What's the situation captain?" This is located above my <style> tag Code: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script language="JavaScript" type="text/javascript"> <script> function redirect() { var x = screen.width; var y = screen.height; var z = x/y; if (z<1) { window.location.replace("alternate destination"); }; else ( ){ // stay here }; }; </script> Reply With Quote 12-21-2014, 01:58 AM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,311 Thanks 82 Thanked 4,754 Times in 4,716 Posts You have extra semicolons in there. In general, don't put a semicolon directly after a right brace }; There are a couple of exceptions, but they don't apply here. What's the point in having the else?? I have a page up with an iframe that's approximately 300px by 405px. When I load up the site in FF and IE, it frames just fine. However, in Chrome and Opera the iframe is shifted upwards and is off-frame. I've tried looking for a solution to center the iframe correctly. Someone said to make a php code that loads 2 different iframes depending on browser (1 iframe for IE/FF and another frame for OP/CH). I have no knowledge of php coding, so I couldn't get it to work. So now, I think I'm limited to redirecting users based on browser type. If the user is using FF or IE, I'll redirect them to my original page. If they're using some other browser, I'll redirect them to a different page without the iframe. I've tried to set up a redirector, but it has trouble distinguishing between FF and Chrome. It treats them exactly the same. Does anyone have any advice on what to do? I've done tons of searching for what seems to be such a small problem. Someone please enlighten me. I am having trouble writing this javascript for my work, normally I would do this in ASP or PHP, but the environment I am working with will only allow javascript for dynamic function. The form has two different select boxes and based on your options selected for select box #1 and select box #2, the hidden input field "redirect" (which is currently empty) would then populate dynamically with the URL associated with that combination mentioned below. The hidden redirect input field (now containing dyanmically generated data) would then pass the new value via HTTP_POST to .net script that will handle the redirect processing step fed to it. Here are the mappings: If selections = Elementary & Vocabulary = http://www.widget.com/content/elem-vocab If selections = Elementary & Writing = http://www.widget.com/content/elem-writing If selections = Elementary & ELD = http://www.widget.com/content/elem-eld If selections = Middle School & Vocabulary = http://www.widget.com/content/midscl-vocab If selections = Middle School & Writing = http://www.widget.com/content/midscl-writing If selections = Middle School & ELD = http://www.widget.com/content/midscl-eld If selections = High School & Vocabulary = http://www.widget.com/content/hiscl-vocab If selections = High School & Writing = http://www.widget.com/content/hiscl-writing If selections = High School & ELD = http://www.widget.com/content/hiscl-eld Here's a snippet of a different method that I tried, but it did not work. I think the above mentioned method would probably be best. Code: <script language="javascript" type="text/javascript"> <!-- function build() { document.fillgaps.redirect.value = "http://www.widget.com/content/" + document.fillgaps.grade.value + "-" + document.fillgaps.solution.value ; //print example: http://www.widget.com/content/ELM-VOC return true; } --> </script> <form name="fillgaps" action="http://www.widget.com/submit.aspx" method="post" onSubmit="return build();"> <input type="hidden" name="redirect" value=""> <table class="elqFormTable" border="0" cellspacing="2" cellpadding="2"> <tr> <td valign="top">Grade:</td> <td> <select name="grade"> <option value="ELM">Elementary</option> <option value="MID">Middle School</option> <option value="HIG">High School</option> </select> </td> </tr> <tr > <td valign="top">Solution:</td> <td> <select name="solution"> <option value="VOC">Vocabulary</option> <option value="WRI">Writing</option> <option value="ELD">ELD</option> </select> <!--truncated code --> Hi, I was working on my web page and noticed that depending on the width of the screen, the Iframe I created would not display correctly. Because of that I needed to come up with a piece of code that would detect the screens horizontal resolution and pick the right Iframe to be loaded. Below are the scenarios that specify which one should be loaded. I am very bad with javascript so could someone help me come up with a piece of code that would load the right frame? Thanks. The web address where the code will go is www.jumbledfun.com/nasa.html. If the horizontal resolution of the screen is less then 1600 I would like this Iframe to be loaded: (It Would Go Under The If Part) Code: <iframe src="http://www.jumbledfun.com/nasaframes/nasalivelr.html" width= "55%" height= "580%" scrolling="no" frameborder="0"/> </iframe> If the horizontal resolution of the screen is 1600 or more I would like this Iframe to be loaded: (It Would Go Under The Else Part) Code: <iframe src="http://www.jumbledfun.com/nasaframes/nasalive.html" width= "100%" height= "300%" scrolling="no" frameborder="0"/> </iframe> This is the format that I would want it in: Code: <script type="text/javascript"> if (condition) { code to be executed if condition is true } else { code to be executed if condition is not true } </script> I have a simple problem that I can't solve. I know that you guys might know how to solve it. I'm using an extension of dreamweaver called Coursebuilder. I'm making an online-examination to improve education especially in a far region of Asia where there's poor quality of education in there. Now, I'm making a multiplication choice type of exam with radio buttons in it and when the "check answer" was clicked, the answer will be explained. It is already done, but the problem is the feedback score. I can't make a feedback score... example the examination is 40/100 score it must appear on the screen at once after a click of a certain button. That's my only problem for now. It will be used in CD format and online. what should i do? All I need is to know how will I put a button that once it was clicked the score in the examination will appear. I'm an amateur web designer, I need your help. Thanks please help me. total score from selected drop down values Hello friends the following is the code i am using without success Code: var numQuestn = 6; function GetScore(form) { var score = 0; var item = 0; var currQuestn = 0; for (i = 0; i < numQuestn; i++) { item = form.q1.selectedIndex; { score += eval(form.q1.options[item].value); } item = form.q2.selectedIndex; { score += eval(form.q2.options[item].value) } item = form.q3.selectedIndex; { score += eval(form.q3.options[item].value) } item = form.q4.selectedIndex; { score += eval(form.q4.options[item].value) } item = form.q5.selectedIndex; { score += eval(form.q5.options[item].value) } item = form.q6.selectedIndex; { score += eval(form.q6.options[item].value) } } form.total.value = score } i am not able to find the error Please help me Thank you in advance Good evening! After spending the last few days wrecking my brain over a simple JavaScript quiz I decided it was time I asked for help. The complete code is right beneath this post. The page will display brief instructions followed by a table containing the quiz. I'm having two rather peculiar problems. The first is with the Score() function which reads as follows: function Score(){ for(i=1;i<=10;i++) if(ans[i]== yourAns[i]) score++; prequiz.score.value= score; } Now unless I'm mistaken (which I am since the score isn't being tabulated correctly) this function essentially uses a for to cycle through both arrays, comparing the user's input against the array containing the right answers. If the contents within index i are the same on both arrays the score increases by one point. Once it cycles through the arrays, it passes score over to prequiz.score.value which will later pass this number to the text box that will display the grade to the user. The problem I'm experiencing is that the score will either be stuck at 2 or will display as 9 (even though all 10 answers were correct). Steps I've taken to try to solve this: Thinking it was the setAnsArray(question, answer) function I added a document.writeline to it. However it showed that the values were being passed correctly to the answer array. Added a document.writeline to the Score() function. Unlike the point above, score always displays as 00000 regardless of how many right answers I provide. The second issue I'm having is that the reset button is not working correctly. If I hit reset and answer the first question, the score will come back as double the score displayed before. Any insight into what is causing this issue is greatly appreciated! Code: <?xml version="1.0" encoding= "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns= "http://www.w3.org/1999/xhtml"> <head> <title>Pre-Quiz!</title> <script type="text/JavaScript"> var ans= new Array(10); var yourAns= new Array(10); var score= 0; ans[0] = "b"; ans[1] = "c"; ans[2] = "c"; ans[3] = "a"; ans[4] = "d"; ans[5] = "c"; ans[6] = "c"; ans[7] = "a"; ans[8] = "b"; ans[9] = "c"; function setAnsArray(question, answer) { yourAns[question]= answer; } function Score(){ for(i=1;i<=10;i++) if(ans[i]== yourAns[i]) score++; prequiz.score.value= score; } </script> </head> <body> <h1>Pre-Quiz</h1> <p>The following test will allow you to evaluate your knowledge in programming prior to starting the course. After completing the test you will receive a score. Should you have any further doubts feel free to bring them with you on the first day of class.</p> </body> <form name="prequiz" action="JavaScript:Score()"> <center> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value= "Reset" /><br><br> </center> <b>Sco </b><input type="text" name="score" disabled=true><br> <hr> <center><table border="3" width="65%" summary= "Questions and options are organized in a table."> <thead> <tr> <th>Question</th> <th>Options</th> </tr> </thead> <tbody> <tr> <td><b>1. The following parameter code is used in which control structure?</b><br> (int i=0; i<= size; i++)<br> </td> <td><input type="radio" name="q1" value="a" onClick="setAnsArray(1, this.value)">a. If<br> <input type="radio" name="q1" value="b" onClick="setAnsArray(1, this.value)">b. For<br> <input type="radio" name="q1" value="c" onClick="setAnsArray(1, this.value)">c. Do-while<br> <input type="radio" name="q1" value="d" onClick="setAnsArray(1, this.value)">d. While</td> </tr> <tr> <td><b>2. What does the command "cout" do?</b><br></td> <td><input type="radio" name="q2" value="a" onClick="setAnsArray(2, this.value)">a. Obtains information from the user.<br> <input type="radio" name="q2" value="b" onClick="setAnsArray(2, this.value)">b. Closes the window.<br> <input type="radio" name="q2" value="c" onClick="setAnsArray(2, this.value)">c. Displays on screen.<br> <input type="radio" name="q2" value="d" onClick="setAnsArray(2, this.value)">d. Pauses a process.</td> </tr> <tr> <td><b>3. What is the origin of name Python? (referring to the programming language)</b><br></td> <td><input type="radio" name="q3" value="a" onClick="setAnsArray(3, this.value)">a. Creator had a pet python.<br> <input type="radio" name="q3" value="b" onClick="setAnsArray(3, this.value)">b. Named after a student of Plato.<br> <input type="radio" name="q3" value="c" onClick="setAnsArray(3, this.value)">c. Named after Monty Python's Flying Circus.<br> <input type="radio" name="q3" value="d" onClick="setAnsArray(3, this.value)">d. Creator was a fan of Greek mythology.</td> </tr> <tr> <td><b>4. What does HTML stand for?</b><br></td> <td><input type="radio" name="q4" value="a" onClick="setAnsArray(4, this.value)">a. HyperText Markup Language<br> <input type="radio" name="q4" value="b" onClick="setAnsArray(4, this.value)">b. Hyper Tools for Managing Languages<br> <input type="radio" name="q4" value="c" onClick="setAnsArray(4, this.value)">c. Heap Text Manager Lead<br> <input type="radio" name="q4" value="d" onClick="setAnsArray(4, this.value)">d. Horde Take Much Lore</td> </tr> <tr> <td><b>5. Who invented JavaScript?</b><br></td> <td><input type="radio" name="q5" value="a" onClick="setAnsArray(5, this.value)">a. Bill Gates<br> <input type="radio" name="q5" value="b" onClick="setAnsArray(5, this.value)">b. Isaac Newton<br> <input type="radio" name="q5" value="c" onClick="setAnsArray(5, this.value)">c. Elvis Java<br> <input type="radio" name="q5" value="d" onClick="setAnsArray(5, this.value)">d. Netscape</td> </tr> <tr> <td><b>6. What is a variable?</b><br></td> <td><input type="radio" name="q6" value="a" onClick="setAnsArray(6, this.value)">a. An unknown.<br> <input type="radio" name="q6" value="b" onClick="setAnsArray(6, this.value)">b. A value that changes.<br> <input type="radio" name="q6" value="c" onClick="setAnsArray(6, this.value)">c. The name for a place in the computer's memory where a certain data is stored.<br> <input type="radio" name="q6" value="d" onClick="setAnsArray(6, this.value)">d. Part of an algebraic expression.</td> </tr> <tr> <td><b>7. What is a compiler?</b><br></td> <td><input type="radio" name="q7" value="a" onClick="setAnsArray(7, this.value)">a. Converts the target file into a .zip .<br> <input type="radio" name="q7" value="b" onClick="setAnsArray(7, this.value)">b. Gathers all documents in one.<br> <input type="radio" name="q7" value="c" onClick="setAnsArray(7, this.value)">c. A program or set of programs that transforms source code from programming language into another computer language.<br> <input type="radio" name="q7" value="d" onClick="setAnsArray(7, this.value)">d. Secret ingridient in KFC's chicken</td> </tr> <tr> <td><b>8. Define portability:</b><br></td> <td><input type="radio" name="q8" value="a" onClick="setAnsArray(8, this.value)">a. Characteristic attributed to a program if it can be used in another OS different from the one it was created in without requiring major rework.<br> <input type="radio" name="q8" value="b" onClick="setAnsArray(8, this.value)">b. Ease to transport the program's disks.<br> <input type="radio" name="q8" value="c" onClick="setAnsArray(8, this.value)">c. How big the size of the program is.<br> <input type="radio" name="q8" value="d" onClick="setAnsArray(8, this.value)">d. Time required to download a program.</td> </tr> <tr> <td><b>9. What is an executable file?</b><br></td> <td><input type="radio" name="q9" value="a" onClick="setAnsArray(9, this.value)">a. A text document containing code.<br> <input type="radio" name="q9" value="b" onClick="setAnsArray(9, this.value)">b. A file in a format the computar can directly execute.<br> <input type="radio" name="q9" value="c" onClick="setAnsArray(9, this.value)">c. A virus.<br> <input type="radio" name="q9" value="d" onClick="setAnsArray(9, this.value)">d. A malicious program.</td> </tr> <tr> <td><b>10. Which of the following is not a programming language? </b><br></td> <td><input type="radio" name="q10" value="a" onClick="setAnsArray(10, this.value)">a. HTML<br> <input type="radio" name="q10" value="b" onClick="setAnsArray(10, this.value)">b. Lua<br> <input type="radio" name="q10" value="c" onClick="setAnsArray(10, this.value)">c. Moolah<br> <input type="radio" name="q10" value="d" onClick="setAnsArray(10, this.value)">d. C++</td> </tr> </tbody> </table></center> </form> </html> Hello everyone, I am using javascript and I have a radio button that the user selects and I have a function to see which button was selected, but i'm trying to use the return of that if statement in another statement. Basically another part of the function is dependent on what the user selects in the radio button. Here is what I have so far (I have some things in there that might not work because i'm trying to figure out what works): Code: <script type="text/javascript"> function getSelectedRadio() { len = document.dates.dep.length // returns the array number of the selected radio button or -1 if no button is selected if (document.dates.dep[0]) { // if the button group is an array (one button is not an array) for (var i=0; i<len; i++) { if (document.dates.dep[i].checked) { return i } } } else { if (document.dates.dep.checked) { return 0; } // if the one button is checked, return zero } // if we get to this point, no radio button is selected return -1; } function Calculate() { var i = getSelectedRadio(); if (i == -1) { alert("Please select if Marine entered Delayed Entry Program"); } else { if (document.dates.dep[i]) { return document.dates.dep[i].value; } else { return document.dates.dep.value; } } if (document.dates.yearDEAF.value < 1985 && document.dates.monthDEAF.value < 01 && document.dates.dayDEAF.value < 01 && first return from above ) { document.dates.yearDEP.value = (document.dates.yearDEAF.value); document.dates.monthDEP.value = (document.dates.monthDEAF.value); document.dates.dayDEP.value = (document.dates.dayDEAF.value); document.dates.yearPEBD.value = (document.dates.yearDEAF.value); document.dates.monthPEBD.value = (document.dates.monthDEAF.value); document.dates.dayPEBD.value = (document.dates.dayDEAF.value); } else if (document.dates.yearDEAF.value < 1985 && document.dates.monthDEAF.value < 01 && document.dates.dayDEAF.value < 01 && second return from above ) { document.dates.yearPEBD.value = (document.dates.yearAFADBD.value); document.dates.monthPEBD.value = (document.dates.monthAFADBD.value); document.dates.dayPEBD.value = (document.dates.dayAFADBD.value); document.dates.yearDEP.value = "N/A"; document.dates.monthDEP.value = "N/A"; document.dates.dayDEP.value = "N/A"; } } </script> I color coded in red the returns i'm trying to reference and where they need to be. Is this possible, and if so how can I do it? I haven't been able to find anything on the internet so far. Any help is greatly appreciated! i'm a total noob with java and can't seem to figure this out. i want to add a bit on to the current url : this is the code i'm using , it just keeps adding... Code: window.location=(window.location+"?p=62"); am i even doing this right.. any help appreciated.. what wrong, it just adds the website to the end of the address bar, and it doesnt redirect???help please <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <div> <h1>hello</h1> <form onsubmit="return go();"> <select name="website" id="website"> <option value="http://www.google.com/">google.com</option> <option value="www.yahoo.com">yahoo.com</option> </select> <script type="text/javascript"> function go() { var s = getElementById("website"); window.location = s.options[s.selectedIndex].value; return false; //prevents the form from being submitted to the server. } </script> <input type="submit"> </form> </div> </body> </html> Hey all im new to the forum as i have just started playing round with javascript but anyway i have this code PHP Code: setTimeout(top.location='profilec.php?id=' + id,4000); and when executed the time delay is not taken into account at all and completly ignored. If i remove the id var from the code and just have PHP Code: setTimeout(top.location='profilec.php?id=',4000); its fine can anyone tell me why this is happening and if there is a solution :-) thanks before hand mike Hi, I'm trying to redirect my users to their profile, but can't figure out how to put the function into the link. sethighlightedValue(); is a function that returns the users username. Is there anyway else to do this? Here's what I got: Code: case RETURN: window.location = "profile.php?user='setHighlightedValue();'"; this.setHighlightedValue(); bubble = false; break; |