|
jkirkerx wrote: value.replace(/^[0-9]+\.[0-9]{2}/, "");
Aren't you replacing those characters with a space? I avoid regex when possible but I am surprised you even get 12500 because it looks like you are replacing characters 0-9 and . with an empty space. When I run this is JSFiddle I get an empty string so I am not sure what you are doing.
|
|
|
|
|
I was thinking the same thing at first. Maybe I need to rethink this.
It's a html element textbox, so like a phone number formatter, it's a currency formatter where you type in say 125.00 or 65.47
It will reject alphabet letters.
I copied it from my phone number formatter, and used the same principals, well at least I think I did.
function formatPhoneNumber12(value) {
if (!value) return value;<br />
const phoneNumber = value.replace(/[^\d]/g, "");<br />
const phoneNumberLength = phoneNumber.length;
if (phoneNumberLength < 4) return phoneNumber;
if (phoneNumberLength < 7) {
return <code>${phoneNumber.slice(0, 3)}-${phoneNumber.slice(3)}</code>;
}
return <code>${phoneNumber.slice(0, 3)}-${phoneNumber.slice(
3,
6
)}-${phoneNumber.slice(6, 9)}</code>;
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
|
I'm back to working on this today. This works in Chrome, but not in firefox. I lose the decimal in firefox.
So in Chrome, I can type 1.23, but in Firefox it types 123
This is a filter or sort of a mask for input element of a number step .01
I thought it was the regex, and monkeyed around for about an hour with it. But it seems to have something to do with the keydown event in Firefox.
I tried this pattern
const pattern = "/^[0-9]+\\.[0-9]{2}/g";
Tried this function style
function formatCurrency(value) {
if (!value) return value;
const pattern = "/^[0-9]+\.[0-9]{2}/g";
return value.replace(pattern, "");
}
And now I'm here. It's just the dot or decimal in FireFox. Maybe it is my regex.
I thought maybe it was the textbox, so I did a console output, same thing.
Oh, I know this function looks weird, like why would I replace what I want to keep. I have no answer for that.
I am stumped... Calling it quits for today. Maybe it's a PHP issue?
document.addEventListener("keydown", (e) => {
const el = e.target;
if (el.classList.contains("currency")) {
el.value = formatCurrency(el.value);
}
});
function formatCurrency(value) {
if (!value) return value;
const pattern = '^(\d+(.\d{0,2})?|.?\d{1,2})$';
console.log('value replace=', value.replace(new RegExp(pattern)));
return value.replace(new RegExp(pattern));
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Changed the input to a textbox, and removed the step attr, and it worked on Firefox
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I'm taking the w3schools tutorial on javascript. In the tutorial it is discussing numerical sort. It says since javascript doesn't sort numerals you need to use a trick of employing a comparison function with sort.
<pre><!DOCTYPE html>
<html>
<body>
<h2>JavaScript Array Sort</h2>
<p>Click the button to sort the array in ascending order.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
const points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points;
function myFunction() {
points.sort(function(a, b){return a - b});
document.getElementById("demo").innerHTML = points;
}
</script>
</body>
</html>
How does function(a, b) get the input a and b? If you could give a detailed message because I'm not getting how it all works.
|
|
|
|
|
The standard sort function takes a comparison function (which "you" supply) as its argument.
As it runs, when it wants to compare two elements of the array being sorted, it calls "your" function with the elements to be compared, and uses the returned value to move the elements according to its algorithm.
The reason for doing it that way is so you can provide whatever sort order you like. for example
function(x,y){return y-x} will sort in reverse numeric order, and function(p,q){console.log(comparing p.toString() to q.toString()); return p-q} will give you a log of all the comparisons made during the sort.
If you don't specify a comparison function, it defaults to a string comparison (which is why it doesn't work with numbers).
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thank you very much for your response Peter_in_2780. It makes more sense, now that I know sort() is looking for a comparison function with two parameters.
|
|
|
|
|
Afternoon all. I'm putting together a kiosk style website and I'm trying to figure out how to make it recover if the connection to the server is lost. I'm using a soap service (i think...) to pass the data. Currently it just hangs up and the page has to be reloaded.
|
|
|
|
|
If it's the client network dropping off, maybe you could use the network information API to detect changes to the connection state?
Network Information API - Web APIs | MDN[^]
Beyond that, without seeing the relevant parts of the code, we can't tell you how to fix it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I am ok with all the fundamentals of javascript but i don't know what to build with it or how to even improve my profile or get a job it is really frustrating to be in this position.
|
|
|
|
|
In my opinion, just JavaScript is not enough to know to be able to do much of anything. I would suggest learning backend technologies as well, maybe some php or .Net.
|
|
|
|
|
It's quite surprising that you don't know what to build since JS may be employed not only on a client but on a server as well. Even I as .NET person had to do node.js service at my current workplace to convert doc file content to html. Unfortunately C# port wasn't mature enough.
But anyways the main usage for JS is SPA applications. Given you have any REST API of your interest you may visualize it's responses.
|
|
|
|
|
|
I have been studying javascript, I want to be a frontend developer but I don't know if jquery is the best option nowadays especially for the UI, is it necessary to study jquery? or can I study something like vue js, node js?
What other web technologies do you recommend?
Thank you so much 
|
|
|
|
|
E-FANIE Rh wrote: vue js, node js? Those are still Javascript.
You need to know CSS and HTML. I use jQuery a ton so I would recommend learning that.
But I also do not see a lot of front end only jobs so I'd also suggest learning the full stack.
|
|
|
|
|
Python, Ruby, PHP; and, we can study a couple of frameworks, Angular. js and Twitter Bootstrap.
|
|
|
|
|
IMO jQuery is not that popular anymore. First of all I'd suggest learning CSS including newer layout techniques such as flexbox and grid . Then on of vue, angular, react. After that, I'd suggest looking deeper into ecosystem tools. Namely webpack as nowadays it is used for a quite variety of tasks. For starters boilerplates provided by frameworks are enough but eventually you'll need to dig deeper
|
|
|
|
|
I built a Web server myself, want to achieve the entire browser minimization,except "JAVA" and "JSP", what method can achieve this effect. There are a lot of examples of browser minimization using "JS" on the internet, but none of them worked for me. Some people mentioned that it might be the ActiveX controls. I don't know what the problem is. Please help me to solve the problem, because I am a rookie, please tell me detailed , thank you very much! Here is an example of using JS for browser minimization that I found on the Internet:
<object id="min" classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize" />
<object id="max" classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Maximize" />
<input type="button" value="minimize" οnclick="min.Click()">
<input type="button" value="maximize" οnclick="max.Click()">
|
|
|
|
|
Javascript cannot change the state of the browser window.
Imagine how annoying it would be if every scammy site you accidentally clicked through to immediately minimized your browser window to hide its nefarious activities!
And no, there is no workaround.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: immediately minimized your browser window to hide its nefarious activities! ... or set full screen (hiding the magic X) with an onanything() handler to restore itself...
Back in the day that caused quite a few heart attacks.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Why would you want to do this?
|
|
|
|
|
function confirmDescConfirmIcon(){
$.sendConfirm({
hideHeader: true,
withIcon: true,
hideClose: true,
autoClose: true,
bgHide: false,
escHide: true,
withCenter: true,
button: {
confirm: 'confirmed',
},
onConfirm: function(){
window.open('test.php','','depended=no,height=-200,width=-200,top=2000,left=2000,toolbar=no,menubar=no,scrollbars=no,location=no,status=no');
}
})};
confirmDescConfirmIcon();
This button page implements "window.open()" to open a new window.
I would like to ask how I can automatically bring the button page to focus if I am browsing another page and the button page is not closed. I don't want to use "window.open" again to bring the button page to focus.
Before, I tried to execute a certain page in the background, and then I wanted to use the "window.location.href" to a page that open a new window of the button page after a period of time, so that the button page becomes the focus of execution, but I failed.
Later I tried a page in the background using "window.location.href" to jump to the button page then the button page automatically become the focus, but failed!
Because I am new for js, trouble a little more detailed, please help me! Thank you very much!
|
|
|
|
|
You have already posted this in the thread immediately below this one.
Do not repost your question. If you do not get a reply, that suggests either you haven't provided enough information, or nobody has a solution for you. Posting the same question again will simply annoy people, and could get you banned from the site.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|