[Solved] My JavaScript program is not working [closed]

Replace if (isNaN(startMiles) = false) by if (isNaN(startMiles)) Remove } after else <script type=”text/javascript”> function calcMPG(){ var startMiles = document.economy.startMilage.value; var endMiles = document.economy.endMilage.value; var gallons = document.economy.galonsUsed.value; if (isNaN(startMiles)) { window.alert(“You can only enter numbers”) } else { document.mpg = document.write((endMiles – startMiles) / gallons) } } </script> 1 solved My JavaScript program is … Read more

[Solved] How to create Regex for 00.00?

Per comment of OP/modified question, if you want 1 or 2 digits, optionally followed by (a period, followed by 1 or 2 more digits), you could use this regex: var regex = /^\d{1,2}(\.\d{1,2})?$/; // The ( ) groups several things together sequentially. // The ? makes it optional. If you want 1 or 2 digits, … Read more

[Solved] Get last 6 months from in Jquery

Javascript style for this piece of code (jQuery not required) : var now = new Date(); var sixMonthsFromNow = new Date(now.setMonth(now.getMonth() – 6)); var sortByQueryString = ‘&fq=lastmodified:[‘ + sixMonthsFromNow.toISOString() + ‘+TO+NOW]’; // &fq=lastmodified:[2013-11-27T08:57:10.089Z+TO+NOW] 1 solved Get last 6 months from in Jquery

[Solved] I have a list of names as , clicking on the name should save it to local storage… code attached [closed]

Try Html <ul class=”namelist”> <li>Liam</li> <li>Noah</li> <li>William</li> <li>James</li> <li>Oliver</li> <li>Benjamin</li> <li>Elijah</li> <li>Lucas</li> </ul> <div id=”divShow”> </div> Jquery <script> $(‘.namelist li’).click(e=>{ localStorage.setItem($(e.currentTarget).text(), $(e.currentTarget).text()); $(‘#divShow’).append(‘<p>’+$(e.currentTarget).text()+'</p>’); }); </script> 3 solved I have a list of names as , clicking on the name should save it to local storage… code attached [closed]

[Solved] Javascript pass function in object value [closed]

If you want buttonFunc to be a function, then do not enclose it in quotation marks, because that makes it a string and not a function: buttonFunc: ‘() => console.log(“test”)’, should be buttonFunc: () => console.log(‘test’), Then you can execute it like so: myArray.forEach(element => { element.buttonFunc(); }); // should console.log(‘test’) solved Javascript pass function … Read more

[Solved] javascript drowdown list

onchange is the correct event. HTML <select onchange=”SelectChanged(this)”> … </select> JS function SelectChanged(obj) { … } Here’s a very simple working example to get you going. solved javascript drowdown list

[Solved] How to pass radio button value with php [closed]

Quick’n dirty solution : <?php $checked=isset($_POST[“radio”]) && $_POST[“radio”]===”oneway”?”checked”:””; ?> <input type=”radio” name=”radio” id=”oneway” value=”oneway” <?php echo $checked;?> /> but actually you should separate logic from template using a template engine like smarty or twig or mustache or whatever… 1 solved How to pass radio button value with php [closed]

[Solved] how can i find if a certain part of the screen is clicked?

You can begin with something like below one. the below code simply add a document wide click listener and retrieve the X and Y coordinates of the pointer click. document.addEventListener(‘click’,function(e){ console.log(e.clientX, e.clientY); }); 0 solved how can i find if a certain part of the screen is clicked?

[Solved] refactoring/making the code better in javascript [closed]

Yes, you should use switch statement here. Chaining so many else if’s is considered bad practice. You can read about switch statement here. https://www.w3schools.com/js/js_switch.asp Code would look something like: function likes(names) { if(names.length<0) { return `${names} likes this`; //return early if possible } let answer=””; switch (names.length) { case 0: answer = `no one likes … Read more

[Solved] Event when onblur input jquery

The solution I’ve found : $(“#address”).on(‘blur focus’, function() { if (this.value==”) { $(‘#button_submit’).css(‘display’, ‘none’); } }); http://jsfiddle.net/np1wkh9p/17/ solved Event when onblur input jquery

[Solved] Get only the first objects of an object in javascript [closed]

Try this: var a = {“Coc Coc”:{“30daysAgo”:1}, Mozilla:{“30daysAgo”:1}, BlackBerry:{“30daysAgo”:1}, Safari:{“30daysAgo”:140}, Firefox:{“30daysAgo”:192}, YaBrowser:{“30daysAgo”:6}, “Internet Explorer”:{“30daysAgo”:72}, “Safari (in-app)”:{“30daysAgo”:40}, “Android Browser”:{“30daysAgo”:3}, Chrome:{“30daysAgo”:1387}, SeaMonkey:{“30daysAgo”:1}, Edge:{“30daysAgo”:7}, Opera:{“30daysAgo”:7}}; var browsers = Object.keys(a).join(“,”); Result: Coc Coc,Mozilla,BlackBerry,Safari,Firefox,YaBrowser,Internet Explorer,Safari (in-app),Android Browser,Chrome,SeaMonkey,Edge,Opera Fiddle 1 solved Get only the first objects of an object in javascript [closed]