Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2003

    not sure where to even start (php question)

    i want 2 boxes side by side, and i want to be able to move stuff from one box to the other like when you click on the to box in outlook and it brings up the list of contacts

    i dont want someones code, just a pointer of where to start. im pretty good at the backend coding side of things, but im rubbish at design..


  2. #2
    Am I right in thinking that you want to have a list of items in one box, where they are selected and at the click of button they are added to another box. There would then be a final submit button when all the items are added?

    If this is what you want I would generate a HTML form that has the following:

    The first box is a <select> field with <options> generated as required.

    The second box could be a <textarea>

    An add button with a JavaScript event handler to add selected items from box 1 into the text value in box 2.

    Then a submit button to send all values from box 2.

    Is this what your thinking of, or did I not understand the question?
    that's me, several medias then a dot and a com

  3. #3
    if you want to do this on the client side then you are talking javascript not php. the problem we've had with javascript in this type of scenario is the lack of event handlers for form objects. there are some but they don't work on lots of browsers.

    if you want to jump back to the server every time you move one of the doodads then doing in in php wouldn't be that hard something like...

    PHP Code:
    if $HTTP_GET_VARS[to_right]!=null{
      array_push($right, $HTTP_GET_VARS[to_right]);
      $i = array_search($HTTP_GET_VARS[to_right], $left);
      $left[$i] = null}

    if $HTTP_GET_VARS[to_left]!=null{
      array_push($left, $HTTP_GET_VARS[to_left]);
      $i = array_search($HTTP_GET_VARS[to_left], $right); 
      $right[$i] = null}

    <div class=left><?
    foreach ($left as $l){
    "<a href=page.php?to_right=$l>$l</a><br>";}?>

    <div class=right><?
    foreach ($right as $r){
    "<a href=page.php?to_right=$r>$r</a><br>";}?>
    this is off the top opf my head without testing and whatnot but something like that would work...

    the third option is using a java applet. I think that is probably the best way to handle it but also the most complicated.

  4. #4
    If the list (on the left, using your outlook example) is short, then I would say it's better to keep it client side with JS than to toss in a whole round trip to the server every time.

    I've actually written a few of these exact mechanisms before, although on a ColdFusion backend rather than PHP.

    My suggestion is to do the following (if my original assumption above about the list is true) :
    1) Use PHP to build an array in Javascript in the HTML that gets sent to the user. You might need/want to make each array element an "object" rather that just a string if you really "care" about some value that's different that is being displayed to the user. (Like show "Joe Brown" but really mean "joe_brown12": OrigList[13].name="Joe Brown";
    OrigList[13].key = "joe_brown12";

    2) When the user clicks the [ >> ] button, have an onclick event that first identifies the selected item, then copies it into another "hidden" javascript array. (So you've have like something like OrigList[OrigList.selectedIndex] and NewList[].
    (sorry, just pseudocode, can assist with details later if need be)

    3) after each item is added to the new array, also add it to the right-side select object. (In general it's easier if you keep your definitive "main" array seperate from a display form element like the select box). It may be easiest to just clobber and redraw the entire box contents (using the contents of the new array) on each add/remove.

    4) When the user clicks submit, walk through the array of "real" values you care about (like joe_brown12) and make a comma-delimited string of these. Assign this list to a "type=hidden" variable in the form that is submitted when the page is submitted. Use PHP on the server to parse through the delimited list and do whatever with it.

    This may seem like it's making it more complex, but it was the way I had to architect some of mine. (I had objects with 4 or 5 attributes so using the right "select" box to store everything didn't make sense in my case) So my suggestion here may be overkill if the data being stored and moved << and >> is simple, but I don't know enough details about your specific case to be sure.

    hope this helps.

    Footnote: to address nnormal's comment about js and form elements: The strategy I've described here only requires being able to get the selectedIndex of a select form object and trap an "onclick" of a button, both very common operations and unlikely to run into any problems except for super-ancient browsers (like IE 3 or NS 3). For great details and sample code you can use, check out:
    (The site is the best resource I've ever found for Javascripting for that matter)...
    Last edited by brianbloom; 03-30-2004 at 08:32 PM.

  5. #5
    Join Date
    Apr 2003
    chers for the help guys, much appreciated

Posting Permissions

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