Click here to Skip to main content
14,271,874 members

JavaScript

 
QuestionHow do I a value from one function and pass it through to another for use Pin
Member 1028754813-Aug-19 11:13
memberMember 1028754813-Aug-19 11:13 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
Richard MacCutchan13-Aug-19 21:33
protectorRichard MacCutchan13-Aug-19 21:33 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
rinave19-Aug-19 15:58
memberrinave19-Aug-19 15:58 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
ZurdoDev21-Aug-19 5:36
professionalZurdoDev21-Aug-19 5:36 
GeneralRe: How do I a value from one function and pass it through to another for use Pin
Richard Deeming21-Aug-19 8:26
mveRichard Deeming21-Aug-19 8:26 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
ZurdoDev21-Aug-19 5:35
professionalZurdoDev21-Aug-19 5:35 
QuestionComparison's in JavaScript Pin
BobInNJ7-Aug-19 10:57
memberBobInNJ7-Aug-19 10:57 
AnswerRe: Comparison's in JavaScript Pin
ZurdoDev7-Aug-19 11:10
professionalZurdoDev7-Aug-19 11:10 
QuestionMessage Closed Pin
30-Jul-19 11:57
memberSmithMasterJerry30-Jul-19 11:57 
QuestionDelete consumer Pin
Member 1453057115-Jul-19 0:09
memberMember 1453057115-Jul-19 0:09 
AnswerRe: Delete consumer Pin
Richard MacCutchan15-Jul-19 0:42
protectorRichard MacCutchan15-Jul-19 0:42 
QuestionRe: Delete consumer Pin
ZurdoDev7-Aug-19 11:08
professionalZurdoDev7-Aug-19 11:08 
QuestionLooking for Bootstrap, TypeScript,Vue and Vue Router Guide to Building a Navigation Bar Pin
Jammer29-Jun-19 2:45
memberJammer29-Jun-19 2:45 
AnswerRe: Looking for Bootstrap, TypeScript,Vue and Vue Router Guide to Building a Navigation Bar Pin
Afzaal Ahmad Zeeshan30-Jul-19 5:37
mveAfzaal Ahmad Zeeshan30-Jul-19 5:37 
Questionhow to open word file in client side Pin
Member 1447396626-Jun-19 1:32
memberMember 1447396626-Jun-19 1:32 
AnswerRe: how to open word file in client side Pin
Richard MacCutchan26-Jun-19 1:45
protectorRichard MacCutchan26-Jun-19 1:45 
QuestionMessage Closed Pin
16-Jun-19 21:53
memberMember 1447282216-Jun-19 21:53 
Question(SOLVED) How to activate button on mouse press? Pin
samflex6-Jun-19 4:39
membersamflex6-Jun-19 4:39 
AnswerRe: How to activate button on mouse press? Pin
Richard Deeming6-Jun-19 5:39
mveRichard Deeming6-Jun-19 5:39 
GeneralRe: How to activate button on mouse press? Pin
samflex6-Jun-19 6:24
membersamflex6-Jun-19 6:24 
GeneralRe: How to activate button on mouse press? Pin
samflex6-Jun-19 7:21
membersamflex6-Jun-19 7:21 
GeneralRe: How to activate button on mouse press? Pin
Richard Deeming6-Jun-19 8:03
mveRichard Deeming6-Jun-19 8:03 
GeneralRe: How to activate button on mouse press? Pin
samflex6-Jun-19 9:47
membersamflex6-Jun-19 9:47 
Questionhow to count product codes from textarea? Pin
Veltix26-May-19 4:11
memberVeltix26-May-19 4:11 
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 + 00002P

So now I have two problems..
First problem, whitelist universal product codes like this:

0FAR12345H00123C + 00001P
0FAR543H00321C + 00001P
0F321H321C + 00001P
0R31H1C + 001P

Second 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: 17

Javascript:

<pre>
"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('\n');

	  event.target.value = values;
	}
	
	function saveToFile() {
	    console.log('Saving to the db');
	    toFile = $('#toFile').val().replace(/\n\r?/g, '<br />');
		$.ajax({
			url: "test2.php",
			type: "POST",
			data: {toFile:toFile}, // serializes the form's elements.
			beforeSend: function(xhr) {
	            // Let them know we are saving
				$('#status').html('Saving...');
			},
			success: function(toFile) {
				// You can get data returned from your ajax call here. ex. jqObj.find('.returned-data').html()
	            // Now show them we saved and when we did
	            var d = new Date();
	            $('#status').html('Saved! Last: ' + d.toLocaleTimeString());
			},
		});
	}

	$('.form').submit(function(e) {
		saveToFile();
		e.preventDefault();
	})


HTML:

<form class="contact-form" method="post">
    <textarea id="toFile" name="toFile" oninput="onInput()"></textarea><br>
    <input type="submit" value="Submit">
</form>

<!-- under here I want show count of product codes + overall count -->

<div id="status"></div>
<div id="info"></div


This is how I want count product codes under textarea + overall count:
Image

This shows what you can only type in textarea (Whitelisted product codes):
Image
AnswerRe: how to count product codes from textarea? Pin
jkirkerx27-May-19 11:14
professionaljkirkerx27-May-19 11:14 

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.