[Solved] Modify item order in select field with javascript [closed]

Fortunately I found the solution in a forum where people are more disposed to help newbie like me. If I was a guru coder, I will probably not need to ask help. <script type=”text/javascript”> function removeIt(){ var sel=document.getElementsByName(‘repeat_period’)[0]; sel.options.remove(0); } removeIt(); </script> http://jsfiddle.net/YgPw4/ solved Modify item order in select field with javascript [closed]

[Solved] Simple JavaScript append array link ids to html doc? [closed]

var myArray = [“id1”, “id2”, “id3”]; var container = document.getElementById(‘container’); myArray.forEach(function(id){ container.innerHTML = container.innerHTML + “<a href=\””+id+”\”>”+id+”</a>” }); http://jsfiddle.net/suwJr/ solved Simple JavaScript append array link ids to html doc? [closed]

[Solved] Javascript function to toggle menu items A, B, C, D [closed]

Use if statements and apply different styles or classes. CSS .hidden { display: none; } HTML & JavaScript <div id=”A” class=”” onclick=”handlePress(‘A’);”>A</div> <div id=”B” class=”hidden” onclick=”handlePress(‘B’);”>B</div> <div id=”C” class=”hidden” onclick=”handlePress(‘C’);”>C</div> <div id=”D” class=”hidden” onclick=”handlePress(‘D’);”>D</div> <script type=”text/javascript”> const letters = [‘A’, ‘B’, ‘C’, ‘D’]; function handlePress(id) { document.getElementById(id).classList.remove(‘hidden’); letters.forEach((letter) => { if (letter !== id) { … Read more

[Solved] How do you match valid integers and roman numerals with a regular expression?

Assuming that you just want decimal integers in regular form (e.g., 1000 would be valid, 1e3 [the same number in scientific notation] would not), the regular expression to validate that is \d+, which means “one or more digit(s).” To have your regular expression allow that, you’d want an alternation, which lets either of two alternatives … Read more

[Solved] Fetch a string between a static pattern in HTML [closed]

You could use DOMParser to convert the string to a document, after which you could querySelectorAll over it to find the elements with translate attributes: const str = `<p translate=”index_word1″ > </p> <strong translate=”index_word2″></strong>`; new DOMParser() .parseFromString(str, ‘text/html’) .querySelectorAll(‘[translate]’) .forEach(element => console.log(element.getAttribute(‘translate’))); 1 solved Fetch a string between a static pattern in HTML [closed]

[Solved] JavaScript loop through two arrays

Do you want something like this? const biscuitsPerCat = (cats, biscuits) => { const share = Math.floor(biscuits / cats.length) const cutoff = biscuits – cats.length * share return cats.reduce((res, cat, idx) => ({…res, [cat]: idx < cutoff ? share + 1 : share}), {}) } console.log(biscuitsPerCat([“Andy”, “Bandy”, “Candy”, “Dandy”], 14)) … which you could then … Read more

[Solved] JavaScript sorting and grouping items in array

Use objects for the grouping. var categories = {}; function incrementBy(category, value) { if (!categories[category]) { categories[category] = 0; } categories[category] += value; } var datasetarr = []; var pos; for(var i = 0; i < arr.length; i++){ console.log(‘unsorted ‘ + arr[i].type + ‘ ‘ + arr[i].quantity); incrementBy(arr[i].type, arr[i].quantity) } for(var category in categories){ console.log(‘sorted … Read more

[Solved] how to make the statement to repeat itself until it gets true?

A possible solution is to use do…while. This code will keep display alert(‘invalid number of grades, please insert again’) and window.prompt until it meets you condition. Then it will window.prompt for user to enter the number. const grades = []; let gradeAmount = Number(prompt(‘insert a number between 1 and 5’)); do{ if(gradeAmount < 1 || … Read more

[Solved] Hide and show divs with text

This are the most used techniques: target element using .index() and .eq() <div id=”clickables”> <div>CLICK 1</div> <div>CLICK 2</div> </div> <div id=”togglables”> <div>text 1</div> <div>text 2</div> </div> $(function(){ $(“#clickables div”).click(function(){ var idx = $(this).index(); $(‘#togglables div’).eq( idx ).slideToggle(); }); }); Pros: you can keep a really clean HTML markup, no need to assign additional classes or … Read more

[Solved] How to implement something like this GIF that using mouse drag and select items

This is the closest you could get with the use of Selectable() provided by JQuery. I have provided a demonstration below: $(function() { $(“#selectable”).selectable(); }); #feedback { font-size: 1.4em; } #selectable .ui-selecting { background: #FECA40; } #selectable .ui-selected { background: #F39814; color: white; } #selectable { margin: 0; padding: 0; width: 60%; display:inline; } #selectable … Read more