Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
string building and hidden form fields
Old 05-29-2007, 01:14 AM string building and hidden form fields
Extreme Talker

Posts: 199
Trades: 0
Hello,

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.
Code:
var select = "";
function selectCounty (cid){ select = cid + "," + select; }
The flash also calls this function to remove a value from the string. The removeVal() function works. though, the *select* variable is not reforming into a string. I'm missing how to then put the array into a form that this is part of.
Code:
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('!!');
}
Please help with these two problems-

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.
empiresolutions is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-29-2007, 02:36 AM Re: string building and hidden form fields
Extreme Talker

Posts: 199
Trades: 0
ok i got a little farther, updated this function to -
Code:
    function unSelectCounty (cid){ 
        // split the *select* string into an array
        select_array = select.split(/,/);
        // remove *cid* value from array
        unselect = removeVal(select_array, cid);
        // reset *select* var
        select = unselect.join(',');
    }
I still need to know about how to attach my *select* var to a hidden form field. this can be passed as a string.
empiresolutions is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to string building and hidden form fields
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15858 seconds with 12 queries