Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    Delimiter of multiple selection scrolling list

    Currently the grabbed value from 'Ecat' is one letter after another. For example, if 'a', 'b', and 'd' are selected, the value would be 'abd'.

    Is there a way I can specifiy a delimiter to make it like this 'a,b,d'

    Code:
    <select name = Ecat multiple="multiple" size="4" style="width:294px;">
    <option value="a">audi</option>
    <option value="b">bmw</option>
    <option value="c">Chevy</option>
    <option value="d">Ford</option>
    <option value="e">Infiniti</option>
    </select>

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Since you used CGI's Vars method to retrieve the form values, $qv->{Ecat} will be a packed string, separated by the "\0" (null) character.

    To separate those values, you'd use the split function.
    Code:
    my @Ecat = split("\0", $qv->{Ecat});
    From there, you can loop over the array elements or join them together or whatever else you want.

  • Users who have thanked FishMonger for this post:

    camaross (05-11-2011)

  • #3
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thank you so much man.

    That is what I did. So it will not be easy to put a delimiter such as ',' in between the option values?




    Quote Originally Posted by FishMonger View Post
    Since you used CGI's Vars method to retrieve the form values, $qv->{Ecat} will be a packed string, separated by the "\0" (null) character.

    To separate those values, you'd use the split function.
    Code:
    my @Ecat = split("\0", $qv->{Ecat});
    From there, you can loop over the array elements or join them together or whatever else you want.
    Last edited by camaross; 05-11-2011 at 02:48 PM.

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    So it will not be easy to put a delimiter such as ',' in between the option values?
    Sure it's easy. You can use a regex to substitute the null char in the packed string with a comma. Or, if you've split that sting into an array, then you can use the join function, or concatenation, or change the list separator to add the commas when outputting or assigning the values to a scalar.

  • Users who have thanked FishMonger for this post:

    camaross (05-11-2011)

  • #5
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    If there are 100 options, 26 letters is not enough. if there is no delimiter, everything will be cramped together. So I can not use strings like 'ab', 'efk', etc, because they will be treated as 5 characters.




    Quote Originally Posted by FishMonger View Post
    Sure it's easy. You can use a regex to substitute the null char in the packed string with a comma. Or, if you've split that sting into an array, then you can use the join function, or concatenation, or change the list separator to add the commas when outputting or assigning the values to a scalar.

  • #6
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    You need to rethink your approach. Using single letters that get strung together like that is a REALLY BAD approach.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •