Skip to content

Tag: javascript

Change form action based on drop down selection

Need form to change it’s action depending on the selection from a specific drop down menu. On change should trigger the script and change the action before user submits. Easier said than done when you’re new to JS.. thanks for any help! Answer Your code is missing the part to get the selected item…

How to make a promise from setTimeout

This is not a realworld problem, I’m just trying to understand how promises are created. I need to understand how to make a promise for a function that returns nothing, like setTimeout. Suppose I have: How do I create a promise that async can return after the setTimeout is ready to callback()? I suppose…

Binary Search in Javascript

I’m trying to implement a binary search algorithm in JavaScript. Things seem okay, but my return statements appear to be returning undefined. Can anybody tell me what’s wrong here? Fiddle: http://jsfiddle.net/2mBdL/ Answer You’re not explicitly returning the recursive inner calls (i.e. retur…

React.js: onChange event for contentEditable

How do I listen to change events for a contentEditable-based control? Code on JSFiddle. Answer See Sebastien Lorber’s answer which fixes a bug in my implementation. Use the onInput event, and optionally onBlur as a fallback. You might want to save the previous contents to prevent sending extra events. I…

Remove duplicate objects from JSON file in JavaScript

This is the current JSON file: I want to remove the duplicate Steve individual from the list. How can I make a new JSON that checks if the object’s name matches and remove any duplicates in JavaScript? Answer You must load the JSON data in to the program and parse that with JSON.parse, like this To filt…

Getting the url parameters inside the html page

I have a HTML page which is loaded using a URL that looks a little like this: I would like to obtain the query string parameters in the URL without using a jsp. Questions Can this be done using Javascript or jQuery? Because I want to test my page using my Node.js local server before deploying it in the remote