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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    How to keep listbox selection saved

    The below code is part of my Page1.html, the resulting value from Ecat will be displayed in Page2.html, where people can go back to Page1.html and edit them again.

    My Perl code works in a way that when people choose to go back to Page1.html, it will pass the user selection results back to $Ecat$. For example, if users selected 'a' and 'c', the value of $Ecat$ will be 'ac'. My question is how can I keep 'a' and 'c' selected within the listbox, when users go back to Page1.html?

    Thank you.

    Code:
    <select name = Ecat value="$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>
    Last edited by camaross; 05-11-2011 at 11:37 AM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by camaross View Post
    The below code is part of my Page1.html, the resulting value from Ecat will be displayed in Page2.html, where people can go back to Page1.html and edit them again.

    My Perl code works in a way that when people choose to go back to Page1.html, it will pass the user selection results back to $Ecat$. For example, if users selected 'a' and 'c', the value of $Ecat$ will be 'ac'. My question is how can I keep 'a' and 'c' selected within the listbox, when users go back to Page1.html?

    Thank you.

    Code:
    <select name = Ecat value="$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>
    you mean when users hit the browser back button?
    In this case the information. Usualy people use sessions to solve this but i don't know what implies this in your case.

    best regards

  • Users who have thanked oesxyl for this post:

    camaross (05-09-2011)

  • #3
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thanks for the reply.

    Not by clicking back button. I use a hidden command to load that page and I am already able to pass back the selection value to $Ecat$.

    Quote Originally Posted by oesxyl View Post
    you mean when users hit the browser back button?
    In this case the information. Usualy people use sessions to solve this but i don't know what implies this in your case.

    best regards

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by camaross View Post
    Thanks for the reply.
    you are welcome,

    Not by clicking back button. I use a hidden command to load that page and I am already able to pass back the selection value to $Ecat$.
    you should realy mark the threads as resolved when you have a solution,

    best regards

  • Users who have thanked oesxyl for this post:

    camaross (05-09-2011)

  • #5
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thanks for the reminder, but I haven't got a solution at all.

    I am only able to pass the value to the overall higher level, not to the specific selection at all. In the above example, I am only able to pass back the value 'ac', I haven't figured out how to keep 'a' and 'c' selected.

    Thanks.

    Quote Originally Posted by oesxyl View Post
    you are welcome,


    you should realy mark the threads as resolved when you have a solution,

    best regards

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by camaross View Post
    Thanks for the reminder, but I haven't got a solution at all.

    I am only able to pass the value to the overall higher level, not to the specific selection at all. In the above example, I am only able to pass back the value 'ac', I haven't figured out how to keep 'a' and 'c' selected.

    Thanks.
    Code:
    <select name = Ecat value="$Ecat$" multiple="multiple" size="4" style="width:294px;">
    <option value="a" selected="selected">audi</option>
    <option value="b">bmw</option>
    <option value="c" selected="selected">Chevy</option>
    <option value="d">Ford</option>
    <option value="e">Infiniti</option>
    </select>
    manage to use this on the Page1
    passing the values back is the bigest problem not this,

    best regards

  • Users who have thanked oesxyl for this post:

    camaross (05-09-2011)

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

    Users can select any of the options. a and c is just one example. Should I add (selected="selected") to all of the options?

    Thanks.


    Quote Originally Posted by oesxyl View Post
    Code:
    <select name = Ecat value="$Ecat$" multiple="multiple" size="4" style="width:294px;">
    <option value="a" selected="selected">audi</option>
    <option value="b">bmw</option>
    <option value="c" selected="selected">Chevy</option>
    <option value="d">Ford</option>
    <option value="e">Infiniti</option>
    </select>
    manage to use this on the Page1
    passing the values back is the bigest problem not this,

    best regards

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by camaross View Post
    Thank you very much.

    Users can select any of the options. a and c is just one example. Should I add (selected="selected") to all of the options?

    Thanks.
    yes all selected options must have ' selected="selected"'
    maybe scrolling_list could help to make this simple, see the man page for CGI.

    best regards

  • Users who have thanked oesxyl for this post:

    camaross (05-09-2011)

  • #9
    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 build the options of the drop down dynamically so that you can set the desired menu options to "selected" as needed.

  • Users who have thanked FishMonger for this post:

    camaross (05-09-2011)

  • #10
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Unfortunately, it does not work.

    Quote Originally Posted by oesxyl View Post
    yes all selected options must have ' selected="selected"'
    maybe scrolling_list could help to make this simple, see the man page for CGI.

    best regards

  • #11
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Any more details?

    So this will not be able to be achieved within html?


    Quote Originally Posted by FishMonger View Post
    You need to build the options of the drop down dynamically so that you can set the desired menu options to "selected" as needed.

  • #12
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    I think this is what I need:

    http://www.plus2net.com/php_tutorial/pb-drop.php

    $t1=$_GET['t1'];
    switch ($t1)
    {
    case "Mon":
    $Mon="selected";
    break;
    case "Tue":
    $Tue="selected";
    break;
    case "Wed":
    $Wed="selected";
    break;
    case "Thu":
    $Thu="selected";
    break;
    case "Fri":
    $Fri="selected";
    break;
    case "Sat":
    $Sat="selected";
    break;
    case "Sun":
    $Sun="selected";
    break;
    }




    Quote Originally Posted by FishMonger View Post
    You need to build the options of the drop down dynamically so that you can set the desired menu options to "selected" as needed.

  • #13
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by camaross View Post
    that means this?
    Code:
    <option value="a"$Ecata$>audi</option>
    and Ecata become ' selected="selected"' if 'a' is selected and '' if not.

    i could be wrong but imo is more simple to generate the page dinamicaly.

    Edit: if you use get is not more simple to pass arguments to javascript and then to manage the selection?

    http://www.javascriptkit.com/jsref/select.shtml

    best regards
    Last edited by oesxyl; 05-10-2011 at 12:29 AM.

  • Users who have thanked oesxyl for this post:

    camaross (05-10-2011)

  • #14
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    This is how I pass back the values in Perl:

    Code:
      $p->var('A1',  $q->escapeHTML(selected))	if index($qv->{Ecat}, 'a') != -1; 
      $p->var('B1',  $q->escapeHTML(selected))   	if index($qv->{Ecat}, 'b') != -1;
      $p->var('C1',  $q->escapeHTML(selected))   	if index($qv->{Ecat}, 'c') != -1;
      $p->var('D1',  $q->escapeHTML(selected))   	if index($qv->{Ecat}, 'd') != -1;
    This is my html:

    Code:
    <select name = Ecat value="$Ecat$" multiple="multiple" size="4" style="width:294px;">
    <option value="a" $A1$>Audi</option>
    <option value="b" $B1$>BMWl</option>
    <option value="c" $C1$>Chevy</option>
    <option value="d" $D1$>Ford</option>
    </select>
    It works for any single selection. For example, if I selected 'd', when I go back, 'd' will be retained.

    However, when I try multiple selections, only the first selection will be retained. For example, if 'b' and 'c' options are selected, when I go back, only 'b' is retained. I narrowed the problem down. It is because only the first one was able to passed back. Now I think it is probably because I can not pass the same value 'selected' to different variables? How could I fix this?

    Thanks.
    Last edited by camaross; 05-10-2011 at 03:37 AM.

  • #15
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Are you using a template module? If so which one?

    The small code snippets that you given aren't enough for use to show you how to fix your script. Please post your complete script and html file.

  • Users who have thanked FishMonger for this post:

    camaross (05-11-2011)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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