[Solved] Strip everything after the last sentence [closed]

You could try a regex replacement: var text=”Hello. World… Lorem? Ipsum 123″; var output = text.replace(/([.?!])(?!.*[.?!]).*$/, “$1”); console.log(output); The replacement logic here says to: ([.?!]) match and capture a closing punctuation (?!.*[.?!]) then assert that this punctuation in fact be the final one .* match and consume all remaining text $ until the end of … Read more

[Solved] Javascript equation producing incorrect value

Per the comments, the issue was that obj.mem1.val1 was being passed to the calculation as a string, resulting in (’90’ + 15) * (0.5343543) or more likely (’90’ + 1) * (0.5343543). Casting it to a number corrects the issue. This may be done like so: Math.floor((+obj.mem1.val1 + i) * (obj.mem2[param][j].val2)) or Math.floor((Number(obj.mem1.val1) + i) … Read more

[Solved] Show or hide a field using jQuery or Ajax [closed]

HTML <label for=”chkEle”>Check This</label> <input type=”checkbox” name=”chkEle” /> <div id=”divEle” style=”display:none;”><date stuff></div> JS $(“input[name=chkEle]”).change(function(e) { $(“#divEle”).toggle(); }); .change is triggered even if the label is clicked instead of the checkbox. This also allows you to dynamically make change in js later. For instance if you wanted to force the checkbox selection on page load, then … Read more

[Solved] How to submit form without reloading? [duplicate]

You can do this using jQuery: http://jquery.com/ Its a javascript framework and one of the methods you can use to do this kind of thing is: $(‘#formID’).submit(function(){ var ajaxURL = ‘/ajax/saveAccountSettings.php’; $.ajax({ type: ‘POST’, url: ajaxURL, data: { username: $(‘#accountForm #username’).val() }, success: function(data){ //Do something } }); return false; }); Probably worth reading up … Read more

[Solved] Generate Tree from flat Array javascript

You could use the level property for indicating the nested position in a helper array. Then iterate the data and build children nodes if necessary. function getTree(array) { var levels = [{}]; array.forEach(function (a) { levels.length = a.level; levels[a.level – 1].nodes = levels[a.level – 1].nodes || []; levels[a.level – 1].nodes.push(a); levels[a.level] = a; }); return … Read more

[Solved] Call php query with javascript [closed]

you’re not trying to get the string “location.hostname”, right? You want the actual hostname from the URL? in that case you have to write the script include as a document.write. document.write(“<script language=”javascript” src=”http://test.com/test.php?q=” + location.hostname + “”><\/script>”); Something like that… WHY are you doing this? 1 solved Call php query with javascript [closed]

[Solved] How do I use a JavaScript variable in PHP? [closed]

Javascript and PHP don’t actually know anything about one another. However, you can use PHP to write to JavaScript. So in my_functions.php you could do this: <?php $myGlobalSongIndex = ‘0’; // or however you want to assign this else…. ?> <script type = “text/javascript”> var song_index = <?php print myGlobalSongIndex; ?>; Then in shortcodes.php on … Read more

[Solved] Facebook app that automatically writes on fans wall, when some fan have birthday? [closed]

Luckily, this is not possible, as it would be pure spam. You would need to authorize every single User with the App, request the publish_actions and user_birthday permissions and store an Extended User Token (that is valid for 60 days). You will never get publish_actions approved by Facebook in their review process, because it´s not … Read more

[Solved] Create a js object from the output of a for loop

A simple Array.prototype.reduce with Object.assign will do // objectMap reusable utility function objectMap(f,a) { return Object.keys(a).reduce(function(b,k) { return Object.assign(b, { [k]: f(a[k]) }) }, {}) } var arr = { “a”: “Some strings of text”, “b”: “to be encoded”, “c”: “& converted back to a json file”, “d”: “once they’re encoded” } var encodedValues = … Read more

[Solved] jQuery – do something once AJAX complete [duplicate]

You can do this: $.post(url, data, function () { alert(“success”); // Call the custom function here myFunction(); }); Or this: // Assign handlers immediately after making the request, // and remember the jqxhr object for this request var jqxhr = $.post(url, data); jqxhr.done(function () { alert(“second success”); // Call the custom function here myFunction(); }); … Read more