[Solved] Unique Random DIV ID using javascript [closed]

Here’s a simple random string generator in a working snippet so you can see what it generates: function makeRandomStr(len) { var chars = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”; var result = “”, rand; for (var i = 0; i < len; i++) { rand = Math.floor(Math.random() * chars.length); result += chars.charAt(rand); } return result; } document.getElementById(“run”).addEventListener(“click”, function() { var … Read more

[Solved] get key value from array

UPDATED: Added eval. Hadn’t noticed that it was in a string. It seems to me that your biggest problem is that it is all wrapped in an array with a single element. You can do: var element = eval(jsonData)[0]; The eval is there to convert from string to a javascript object. Then, to access anything … Read more

[Solved] Custom status with guild number [closed]

Alright, I am using this in my bot too: here is the code //… client.on(‘ready’, () => { //… client.user.setActivity(‘othertext’ + client.guilds.cache.size, {type : ‘PLAYING’}) } client.on(‘guildCreate’, guild => { //same code as ‘ready’ }) client.on(‘guildDelete’, guild => { //also the same code as ‘ready’ }) Now this was from my human memory but this … Read more

[Solved] Find Min and Max with javascript [closed]

Math.min and Math.max return the minimum and maximum values. Since you want your function to print it out to the console, use console.log to print out these values, along with a templated string to have it in the format you want. const minAndMax = (arr) => console.log(`The minimum value in the array is: ${Math.min(…arr)}, the … Read more

[Solved] Multiple image rollover in javascript with for loop

I would recommend you don’t include inline event attributes at each element. But I would consider including an inline html5 data- attribute with the message associated with the elements: <img src=”https://stackoverflow.com/questions/24593698/images/img1.jpg” data-msg=”Hi, How r u?” width=”100″ height=”100″> <!– etc –> Then you can bind the same rollover functions to each element using a loop as … Read more

[Solved] How to check null value in json?

Try this code , var data = { “mname”: [ { “Mname”: “abc”, “pname”: [], “rewards”: null } ] } $.each( data.mname , function( key, value ) { if(value.rewards == null || value.rewards == undefined){ // Add your codes/logic } }); 1 solved How to check null value in json?

[Solved] Modify JSON array in Javascript

This is how you do it in plain javascript (es6) const mergePrice = data => data.reduce((result, val) => { const { quoteId, price, userName } = val; let obj = result.find(o => o.quoteId === quoteId); if (!obj) { obj = { quoteId, userName, price: [] }; result.push(obj); } obj.price.push(price); return result; }, []); const merged … Read more

[Solved] radion button selection based on input value [closed]

You can do in this way $checked = $_POST[‘gender’]; <input type=”radio” value=”male” <?php if($checked==”male”){echo “checked”}; ?> > Male <input type=”radio” value=”female” <?php if($checked==”female”){echo “checked”}; ?> > Female 1 solved radion button selection based on input value [closed]

[Solved] How to individually increase or decrease a value using jquery

DEMO $(document).ready(function () { $(“.quantity-adder .add-action”).click(function () { if ($(this).hasClass(‘add-up’)) { var text = $(this).parent().parent().parent().find(“[name=quantity]”, ‘.quantity-adder’) text.val(parseInt(text.val()) + 1); } else { var text = $(this).parent().parent().parent().find(“[name=quantity]”, ‘.quantity-adder’) if (parseInt(text.val()) > 1) { text.val(parseInt(text.val()) – 1); } } }); }); I added the .parent() so that then find the proper text to increase 7 solved How … Read more

[Solved] Javascript comma list but has an and at the last one

This should work. function createSentence(array) { if (array.length == 1) { return array[0]; } else if (array.length == 0) { return “”; } var leftSide = array.slice(0, array.length – 1).join(“, “); return leftSide + ” and ” + array[array.length – 1]; } console.log(createSentence([“dogs”, “cats”, “fish”])); console.log(createSentence([“dogs”, “cats”])); console.log(createSentence([“dogs”])); console.log(createSentence([])); 6 solved Javascript comma list but … Read more