[Solved] format a 12 digit number in XXXX XXXX XXXX format using javascript

You can use selectionEnd to control the position of cursor var target = document.querySelector(‘.creditCardText’); target.addEventListener(“keyup”, function() { var position = target.selectionStart; var prevVal = target.value; var newVal = prevVal.split(” “).join(“”); // remove spaces if (newVal.length > 0) { newVal = newVal.match(new RegExp(‘.{1,4}’, ‘g’)).join(” “); } target.value = newVal; for (var i = 0; i < … Read more

[Solved] How Do I Execute btoa(string); using HTML and JS

Javascript has a built in atob and btoa function. <script type=”text/javascript”> function doAtob() { var val = document.getElementById(“inputbox”).value; var out = document.getElementById(“outval”); out.appendChild(document.createTextNode(atob(val))); } </script> <input id=”inputbox” type=textbox /> <button onclick=’doAtob()’>Do it!</button> <span id=”outval” /> solved How Do I Execute btoa(string); using HTML and JS

[Solved] AppendChild Is Not working with textcontent (javascript) [closed]

textContent replaces all the content in the element. http://jsfiddle.net/2nmL7v5b/6/ You have to something like this var infoDiv = document.createElement(“div”); infoDiv.setAttribute(“class”, “text-block”); var bio = document.createElement(“strong”); bio.textContent = “Bio”; infoDiv.appendChild(bio); var spanElem = document.createElement(“div”); spanElem.textContent = “Full”; infoDiv.appendChild(spanElem) document.getElementsByTagName(“body”)[0].appendChild(infoDiv) <body> </body> Or if you don’t want to use span tag you can use innerHTML also like … Read more

[Solved] Detect alternating key events

You only need one event listener, and you need to define the a key press state variable (x) outside of the listener function so that it can be referenced by subsequent executions of the listener function. You also need to make sure that you reset the a key press variable after the b key press. … Read more

[Solved] Find piece of string inside array and do something if I can find it

Your question still isn’t explained very well, but I think I have it. You’re asking why this returns true: if($(this).html().indexOf(“Title A”) != -1) { //should get here } But this doesn’t: var titles = [“Title A”]; var realTitle = $(this).html(); if (titles.indexOf(realTitle) > -1) { //should get here } The difference has to do with … Read more

[Solved] Validation Form with PHP or Javascript [closed]

if the visitor fills out a field phone then allowed only enter numbers. and if the visitor fills out a field phone then allowed only enter email. Check this out function validateForm(){ var x = document.getElementById(‘name’); var email = document.getElementById(’email’); var num = document.getElementById(‘number’); var size = document.getElementById(‘size’); var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; var atpos=email.value.indexOf(“@”); var … Read more

[Solved] Parse string using javascript [closed]

You can find the pos of the “He ” using the indexOf method and then get the position of the next line-break to remove that line using the substring method. var someString = “Hello world,\n” + “He like cats and dogs\n” + “Bye bye”; var pos = someString.indexOf(‘He ‘); var nextLineBreak = someString.indexOf(‘\n’, pos); var … Read more

[Solved] Javascript code isn’t working. Does anyone know why?

<!DOCTYPE html> <html> <head> <title>form</title> </head> <body> <input id=”txtQuery” type=”text” /> <button id=”btnRequest”>Request</button> <pre id=”txtResponse”><pre> <script type=”text/javascript” src=”https://code.jquery.com/jquery-1.12.4.min.js”></script> <script> $(document).ready(function(){ $(“#btnRequest”).click(function(){ //Doing a JSON request to wikipedia api $.getJSON(“https://en.wikipedia.org/w/api.php?action=opensearch&format=jsonfm&search=”+ $(“#txtQuery”).val() + “&namespace=0&limit=10&redirects=resolve&format=json&callback=?”, function(data) { $(“#txtResponse”).html(JSON.stringify(data,null,4)); }); }); }); </script> </body> </html> 2 solved Javascript code isn’t working. Does anyone know why?

[Solved] how do i split the url using split method by checking all the image extension

You can always try to do it like this; var imgUrl = “http://sits/productimages/00670535922278.png?sw=350&sh=350;”; var splitterArray = [‘.jpeg’, ‘.png’, ‘.jpg’, ‘.gif’]; for (var i = 0; i < splitterArray.length; i++) { var imgUrlArray = imgUrl.split(splitterArray[i]); if (imgUrlArray.length > 1) { //Do your thing here } } You use a array of your extensions that will be … Read more