[Solved] Array’s elements in JavaScript [duplicate]

This is an approach using Array.reduce() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce First I determine for each unique value in the array how many times it does occur, by returning an object like {“1”: 3, “2”: 3, “3”: 1} Then I determine which are the values occurred most of the times in the array, by returning an object like {“count”: … Read more

[Solved] Please help with ajax script + jquery [closed]

<script type=”text/javascript”> $(document).ready(function() { $(“#sendmessage”).submit(function() { $(“#note”).fadeIn(1000).html(‘PLease wait…’); var str = $(this).serialize(); $.ajax({ type: “POST”, url: “/send.php”, data: str, success: function(data) { $(“#note”).html(data); $(“#fields”).hide(); }, error: function() { $(“#note”).html(‘Error’); } }); return false; }); }); solved Please help with ajax script + jquery [closed]

[Solved] exam with timer in javascript [closed]

you could store the question and answers in a multidimensional array like follows // [question number, answer, question] var qanda =[ [1,15,”Add 11 + 4″], [2,7,”Add 4 + 3″], [3,7,”Subtract 9 – 2″] ]; function getQuestion(n){ document.getElementById(“disp_question”).innerHTML = qanda[n][2]; document.getElementById(“intp_div”).style.display = “block”; } function checkAnswer(n){ if(document.getElementById(“intp_answer”).value != undefined){ if(document.getElementById(“intp_answer”).value == qanda[n][1]){ alert(“correct”) }else{ alert(“incorrect”) } … Read more

[Solved] How to create a javascript function that will remember the user input and then display summary

This is a simple task, basically we need a button that when we click it outputs form elements inside some output element, I will use a div. To get elements in JavaScript we can assign id‘s to elements and do this: document.getElementById(“elementIdName”) to retrieve those values. From there we can use onclick which will activate … Read more

[Solved] Need help linking 2k files into html [closed]

Given your specific situation as explained in the chat, you have no access to the ‘back end’ you DO have access and permission to change the directory-structure and file-names of the course-materials (pdf-files) current path & filenaming conventions are a mess (don’t exist) and unpredictable there is currently nothing linking course-codes with course-descriptions/course-materials every course … Read more

[Solved] What’s way to define variable is better and why?

Javascript is functionally scoped, so in the first way, a is defined globally, while in the second, it’s defined in the scope of the function DoSomething. Also note that in the first method, you’re calling DoSomething incorrectly. Instead of calling it after the timeout, you’re calling it immediately, and passing it’s result (which is nothing … Read more

[Solved] how to show an alert box In javascript

If you want to check if the user has entered a number or not, you could use isNaN: function foo() { var a = document.getElementById(“inputField”).value; if (isNaN(a)) { alert(“Must input numbers”); } else { alert(“its a number”); } } where inputField is the ID of your input field. Of course you can use if (isNaN(a)) … Read more

[Solved] Get last “ordered” number [closed]

Here’s working code. Although I don’t like just giving you the answer. This is something you have to practice and learn how to do on your own. Take the time to understand what I did. Also, this solution can be improved a lot, just something that I did quickly and works. The algorithm in action: … Read more

[Solved] How to write Java script that advances to a link after a link has been clicked “X” # of times [closed]

Try this. Its simple but you get the idea. Rest you should try to accomplish yourself. var clicks = 0; document.getElementById(‘button’).onclick = function(){ clicks++; if(clicks == 5) { window.location.href=”www.yourlink.com”; } } <button id=”button”> Click </button> solved How to write Java script that advances to a link after a link has been clicked “X” # of … Read more

[Solved] modify array of objects – javascript

Aggregation like this be handled by Array.reduce(). For example: const arr = [ {KEY1: “VALUE1”, NAME: “VALUE2”, PID: “VALUE36”}, {KEY11: “VALUE1”, NAME: “VALUE2”, PID: “VALUE47”}, {KEY11: “VALUE1”, NAME: “VALUE4”, PID: “VALUE49”}, {KEY11: “VALUE1”, NAME: “VALUE4”, PID: “VALUE43”}, ] // Objects are basically associative arrays in JS, so… // (For each item in arr, add or … Read more

[Solved] Javascript – is it possible to make a loop using functions? [closed]

Here’s how you can repeat some code with a recursive timer function: (function repeat(n){ if (!n) return; console.log(“do something”); setTimeout(repeat, 0, n-1); })(4); Contrary to a (non tail optimized) recursion, there’s no cumulative memory consumption here. This kind of construct is useful in some cases. But just avoiding the for and while keywords doesn’t strike … Read more