Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by ank5
at 2024-11-03 09:09:25
Point:500 Replies:4 POST_ID:828774USER_ID:11616
Topic:
JavaScript;Web Languages/Standards;Scripting Languages
I need to write a Javascript function which accepts two comma separated values
(function() { m2.getStatus = function(folderObjIDs, docObjIDs) { };})(); 1:2:3:4:5:6:
Now both these parameters could have multiple values each separated with a comma.
Example, folderObjIDs could have 'a,b,c' and docObjIDs could have 'c,d,e'.
I need to check which value is common in both the parameters, and then alert it to the user ('c' in the example above).
Can someone please let me know how this can be done?
Thank you
Accepted Solution
Expert: leakim971 replied at 2024-11-03 15:27:54
500 points EXCELLENT
Uncaught TypeError: Object [object Array] has no method 'split'
that mean you don't pass << two comma separated values >>
m2.getStatus = function(folderObjIDs, docObjIDs) {var f1 = "";var f2 = ""; if(typeof folderObjIDs!="string") { alert("folderObjIDs is not string, hope it's an array..."); f1 = folderObjIDs } else { f1 = folderObjIDs.split(","); } if(typeof docObjIDs!="string") { alert("docObjIDs is not a string, hope it's an array..."); f2 = docObjIDs; } else { f2 = docObjIDs.split(","); } var f3 = []; for(var i=0;i<f1.length;i++) for(var j=0;j<f2.length;j++) if(f1[i]==f2[j]) f3.push(f1[i]); return f3.join(","); }; 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:
Expert: duncanb7 replied at 2024-11-03 12:00:14
Try to use split() function in javascript and its syntax from www.w3schools.com
folderObjIDs ='a,b,c';
array=folderObjIDS.split(",");
alert(array[0]); //// that you can get "a"
so next step will be easier for you for any operation for those two string comparsion
by your javascript function
folderObjIDs ='a,b,c';
array=folderObjIDS.split(",");
alert(array[0]); //// that you can get "a"
so next step will be easier for you for any operation for those two string comparsion
by your javascript function
Author: ank5 replied at 2024-11-03 10:10:37
Thank you. I tried that but it gives me an error
Uncaught TypeError: Object [object Array] has no method 'split'
Uncaught TypeError: Object [object Array] has no method 'split'
Expert: leakim971 replied at 2024-11-03 09:24:09
test page : http://jsfiddle.net/URzgr/1/
m2.getStatus = function(folderObjIDs, docObjIDs) { var f1 = folderObjIDs.split(","); var f2 = docObjIDs.split(","); var f3 = []; for(var i=0;i<f1.length;i++) for(var j=0;j<f2.length;j++) if(f1[i]==f2[j]) f3.push(f1[i]); return f3.join(","); }; 1:2:3:4:5:6:7:8:9: