how to count product codes from textarea?
-
I want count in my textarea product codes.
I have whitelist for product codes so I cant type or write anything else into textarea.
Found bad issue, I can write only static product codes like (first 16 is product code other 6 is how many products it is in list...):0FAR12345H00123C + 00001P
0FAR54321H00321C + 00001P
0FAR54321H00321C + 00002PSo now I have two problems..
First problem, whitelist universal product codes like this:0FAR12345H00123C + 00001P
0FAR543H00321C + 00001P
0F321H321C + 00001P
0R31H1C + 001PSecond problem is how to count these product codes under textarea + overall count.
Example under textarea counts:
0FAR12345H00123C: 5
0FAR543H00321C: 2
0F321H321C: 6
0R31H1C: 4
Overall: 17Javascript:
"use strict";
toFile.focus();var timeoutId; $('#toFile').on('keypress', function() { console.log('Textarea Change'); clearTimeout(timeoutId); timeoutId = setTimeout(function() { // Runs 3 second (3000 ms) after the last change saveToFile(); }, 3000); }); toFile.addEventListener("keyup", event => { const data = toFile.value.split("\\n"); const result = data.unique(); info.textContent = result.length !== data.length ? "Duplicate removed" : ""; toFile.value = result.join('\\n'); }); if (!Array.prototype.unique) { Object.defineProperty(Array.prototype, "unique", { configurable: false, // these 3 properties default to false so not needed enumerable: false, // But have added them just to show their availability. writable: false, value: function() { const existing = {}; return this.filter(a => existing\[a\] = !existing\[a\] ? true : false); } }); } else { throw new Error("Array.prototype.unique already defined."); } const CODE = \['Product', 'Codes', 'Here'\]; const reg = /^(\[a-zA-Z0-9\]{1,6})$/; // Ensure values been inserted are in correct format function onInput() { let values = event.target.value .split('\\n') .map(v => { v = v.trim().toUpperCase(); if (v.length <= 16) { if (CODE\[0\].substr(0, v.length) != v && CODE\[1\].substr(0, v.length) != v) { v = v.substr(0, v.length - 1); } } else if (!v.substr(16, 22).match(reg)) { // at the moment static 16 product code lenght + 6 is count of products. v = v.substr(0, v.length - 1); } return v; }).join('
-
I want count in my textarea product codes.
I have whitelist for product codes so I cant type or write anything else into textarea.
Found bad issue, I can write only static product codes like (first 16 is product code other 6 is how many products it is in list...):0FAR12345H00123C + 00001P
0FAR54321H00321C + 00001P
0FAR54321H00321C + 00002PSo now I have two problems..
First problem, whitelist universal product codes like this:0FAR12345H00123C + 00001P
0FAR543H00321C + 00001P
0F321H321C + 00001P
0R31H1C + 001PSecond problem is how to count these product codes under textarea + overall count.
Example under textarea counts:
0FAR12345H00123C: 5
0FAR543H00321C: 2
0F321H321C: 6
0R31H1C: 4
Overall: 17Javascript:
"use strict";
toFile.focus();var timeoutId; $('#toFile').on('keypress', function() { console.log('Textarea Change'); clearTimeout(timeoutId); timeoutId = setTimeout(function() { // Runs 3 second (3000 ms) after the last change saveToFile(); }, 3000); }); toFile.addEventListener("keyup", event => { const data = toFile.value.split("\\n"); const result = data.unique(); info.textContent = result.length !== data.length ? "Duplicate removed" : ""; toFile.value = result.join('\\n'); }); if (!Array.prototype.unique) { Object.defineProperty(Array.prototype, "unique", { configurable: false, // these 3 properties default to false so not needed enumerable: false, // But have added them just to show their availability. writable: false, value: function() { const existing = {}; return this.filter(a => existing\[a\] = !existing\[a\] ? true : false); } }); } else { throw new Error("Array.prototype.unique already defined."); } const CODE = \['Product', 'Codes', 'Here'\]; const reg = /^(\[a-zA-Z0-9\]{1,6})$/; // Ensure values been inserted are in correct format function onInput() { let values = event.target.value .split('\\n') .map(v => { v = v.trim().toUpperCase(); if (v.length <= 16) { if (CODE\[0\].substr(0, v.length) != v && CODE\[1\].substr(0, v.length) != v) { v = v.substr(0, v.length - 1); } } else if (!v.substr(16, 22).match(reg)) { // at the moment static 16 product code lenght + 6 is count of products. v = v.substr(0, v.length - 1); } return v; }).join('
Your pretty vague in saying what exactly your having trouble with. I'm not going to write code for you, but think of part numbers as words, gathering each word and then count the occurrence of each word. This is done all the time, using words like "apple, orange" so you get a count of "apples" and "oranges" Perhaps search the internet for a JavaScript example of counting words! Start again from scratch, and write functions to do the following. So get all the text in the textarea Gather and count each occurrence of a word and push the words into an array and increment the counter Then loop the array, and qualify the words as a part number, remove the ones that don't qualify. Now you have an array or words and the count. Then do something with the array of words. Now go back and write event listeners to trigger your main function.
If it ain't broke don't fix it Discover my world at jkirkerx.com
-
I want count in my textarea product codes.
I have whitelist for product codes so I cant type or write anything else into textarea.
Found bad issue, I can write only static product codes like (first 16 is product code other 6 is how many products it is in list...):0FAR12345H00123C + 00001P
0FAR54321H00321C + 00001P
0FAR54321H00321C + 00002PSo now I have two problems..
First problem, whitelist universal product codes like this:0FAR12345H00123C + 00001P
0FAR543H00321C + 00001P
0F321H321C + 00001P
0R31H1C + 001PSecond problem is how to count these product codes under textarea + overall count.
Example under textarea counts:
0FAR12345H00123C: 5
0FAR543H00321C: 2
0F321H321C: 6
0R31H1C: 4
Overall: 17Javascript:
"use strict";
toFile.focus();var timeoutId; $('#toFile').on('keypress', function() { console.log('Textarea Change'); clearTimeout(timeoutId); timeoutId = setTimeout(function() { // Runs 3 second (3000 ms) after the last change saveToFile(); }, 3000); }); toFile.addEventListener("keyup", event => { const data = toFile.value.split("\\n"); const result = data.unique(); info.textContent = result.length !== data.length ? "Duplicate removed" : ""; toFile.value = result.join('\\n'); }); if (!Array.prototype.unique) { Object.defineProperty(Array.prototype, "unique", { configurable: false, // these 3 properties default to false so not needed enumerable: false, // But have added them just to show their availability. writable: false, value: function() { const existing = {}; return this.filter(a => existing\[a\] = !existing\[a\] ? true : false); } }); } else { throw new Error("Array.prototype.unique already defined."); } const CODE = \['Product', 'Codes', 'Here'\]; const reg = /^(\[a-zA-Z0-9\]{1,6})$/; // Ensure values been inserted are in correct format function onInput() { let values = event.target.value .split('\\n') .map(v => { v = v.trim().toUpperCase(); if (v.length <= 16) { if (CODE\[0\].substr(0, v.length) != v && CODE\[1\].substr(0, v.length) != v) { v = v.substr(0, v.length - 1); } } else if (!v.substr(16, 22).match(reg)) { // at the moment static 16 product code lenght + 6 is count of products. v = v.substr(0, v.length - 1); } return v; }).join('
When I am developing a character count for my text area on my website. Right now, it says NaN because it seems to not find the length of how many characters are in the field, at beginning start with 0, so the number should be 500. In the console in chrome developer tools, no error occurs on my code is on the site, after though tried to use jQuery a regular JavaScript for the character count for the text area field, but nothing seems to work for more click JAVA training in Delhi