I'm trying to get this script to work, but my deep rooted PHP syntax is messing my JS up.
I have a flash file that calls this JS function. It basically adds a number to a comma separated string. this works fine.
Expand|Select|Wrap|Line Numbers
- var select = "";
- function selectCounty (cid){ select = cid + "," + select; }
Expand|Select|Wrap|Line Numbers
- function unSelectCounty (cid){
- // split the *select* string into an array
- var select_array = select.split(/,/);
- // remove *cid* value from array
- unselect = removeVal(select_array, cid);
- // reset *select* var
- select = "";
- for (i=0;i<unselect.length;i++){ if (unselect[i] != ''){ select = unselect[i] + "," + select; } }
- }
- function removeVal(arr, valToRemove){
- // Normalize to a string like !val!!val!!val!
- var s = '!' + arr.join('!!') + '!';
- // Remove targeted values with delimiters
- s = s.replace(new RegExp('!' + valToRemove + '!', 'g'), '');
- // Remove delimiter added to end in step 1
- s = s.replace(/^!/, '');
- // Remove delimiter added to start in step 1
- s = s.replace(/!$/, '');
- // Convert to array
- return s.split('!!');
- }
1) i cant get the *select* string in unSelectCounty() to reform correctly.
2) i am unsure what to write so that the value of *select* is passed in POST form array. it can accept it either as an array or a string.
Thanks.