Click here to Skip to main content
15,894,109 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Uploading image using JQuery AJAX Pin
Alex Dunlop10-Nov-21 22:14
Alex Dunlop10-Nov-21 22:14 
GeneralRe: Uploading image using JQuery AJAX Pin
Richard Deeming10-Nov-21 22:17
mveRichard Deeming10-Nov-21 22:17 
AnswerRe: Uploading image using JQuery AJAX Pin
jkirkerx16-Nov-21 13:50
professionaljkirkerx16-Nov-21 13:50 
GeneralRe: Uploading image using JQuery AJAX Pin
Richard Deeming17-Nov-21 0:46
mveRichard Deeming17-Nov-21 0:46 
GeneralRe: Uploading image using JQuery AJAX Pin
jkirkerx17-Nov-21 6:18
professionaljkirkerx17-Nov-21 6:18 
Questionhow do you paint objects with two different colors in the for repetition structure Pin
Member 1541326530-Oct-21 3:38
Member 1541326530-Oct-21 3:38 
AnswerRe: how do you paint objects with two different colors in the for repetition structure Pin
Richard MacCutchan30-Oct-21 4:25
mveRichard MacCutchan30-Oct-21 4:25 
GeneralRe: how do you paint objects with two different colors in the for repetition structure Pin
Member 1541326530-Oct-21 9:07
Member 1541326530-Oct-21 9:07 
AnswerRe: sytax error unexcepted token Pin
OriginalGriff5-Oct-21 21:20
mveOriginalGriff5-Oct-21 21:20 
GeneralRe: sytax error unexcepted token Pin
Richard Deeming5-Oct-21 21:44
mveRichard Deeming5-Oct-21 21:44 
GeneralRe: sytax error unexcepted token Pin
OriginalGriff5-Oct-21 21:52
mveOriginalGriff5-Oct-21 21:52 
Questiondata import via API Pin
Francesco Reboldi23-Sep-21 19:28
Francesco Reboldi23-Sep-21 19:28 
AnswerRe: data import via API Pin
Afzaal Ahmad Zeeshan23-Sep-21 23:47
professionalAfzaal Ahmad Zeeshan23-Sep-21 23:47 
GeneralRe: data import via API Pin
Afzaal Ahmad Zeeshan24-Sep-21 4:11
professionalAfzaal Ahmad Zeeshan24-Sep-21 4:11 
GeneralRe: data import via API Pin
Francesco Reboldi24-Sep-21 5:13
Francesco Reboldi24-Sep-21 5:13 
GeneralRe: data import via API Pin
Francesco Reboldi25-Sep-21 6:26
Francesco Reboldi25-Sep-21 6:26 
QuestionRegex not keeping the . or decimal with currency value with keydown event. Pin
jkirkerx23-Sep-21 9:06
professionaljkirkerx23-Sep-21 9:06 
AnswerRe: Regex not keeping the . or decimal with currency value with keydown event. Pin
Member 1532961323-Sep-21 9:32
Member 1532961323-Sep-21 9:32 
GeneralRe: Regex not keeping the . or decimal with currency value with keydown event. Pin
jkirkerx23-Sep-21 9:39
professionaljkirkerx23-Sep-21 9:39 
GeneralRe: Regex not keeping the . or decimal with currency value with keydown event. Pin
Member 1532961324-Sep-21 1:07
Member 1532961324-Sep-21 1:07 
AnswerRe: Regex not keeping the . or decimal with currency value with keydown event. Pin
jkirkerx29-Sep-21 12:19
professionaljkirkerx29-Sep-21 12:19 
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 input value is falsy eg if the user deletes the input, then just return
    if (!value) return value;

    // clean the input for any non-digit values.
    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")) {
        // console.debug(el.id, el.value);
        el.value = formatCurrency(el.value);
    }
});

function formatCurrency(value) {

    // if input value is false, eg if the user deletes the input, then just return
    if (!value) return value;

    // clean the input for any non-digit values except .
    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

GeneralRe: Regex not keeping the . or decimal with currency value with keydown event. [Perhaps Solved] Pin
jkirkerx29-Sep-21 13:18
professionaljkirkerx29-Sep-21 13:18 
QuestionHow does the compare function work with numerical sort? Pin
Ryan Blake 202126-Aug-21 15:51
Ryan Blake 202126-Aug-21 15:51 
AnswerRe: How does the compare function work with numerical sort? Pin
Peter_in_278026-Aug-21 18:22
professionalPeter_in_278026-Aug-21 18:22 
GeneralRe: How does the compare function work with numerical sort? Pin
Ryan Blake 202128-Aug-21 13:45
Ryan Blake 202128-Aug-21 13:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.