SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy dynmic select boxes

    hi all

    How can we take dynamically name from a select box and i want this names in the next page using post or get method ?

    ie I want the name or value of a particular select box from one page to next page (note that all the select box i am creating dynamically). How can i take this value or name to next page using php's post method


    pleae help me

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why must the name be dynamic?

    i suppose you could use a hidden form field with a known name, and set the value to the dynamic name of the select menu. then use the known name to find the dynamic name when receiving the form.

    if you could provide more info, there may be a much easier solution.

  3. #3
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    i have come up wih a sloution please see whether it is possible


    <form name="form1" method="post" action="select1.php">
    <div align="center">
    <p>
    <select name="number[]" class="text" id="number[]" multiple>
    <option value="Select">Select</option>
    <option value="1">1</option>
    <option value="3">3</option>
    <option value="2">2</option>
    <option value="4">4</option>
    </select>
    <select name="number[]" class="text" id="number[]" multiple>
    <option value="Select">Select</option>
    <option value="12">12</option>
    <option value="32">32</option>
    <option value="22">22</option>
    <option value="42">42</option>
    </select>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </div>
    </form>


    <?php
    if (count($_POST['number']) > 0) {
    foreach ($_POST['number'] as $blah) {

    if ($blah<>'Select'){echo $blah . '<br>';}

    }
    }

    ?>

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, that will work just fine but it will group them all together into 1 array. if you want the selections from each menu to be seperated from other menus, use a multidimensional array.
    Code:
    <select name="number[0][]" ...
    
    <select name="number[1][]" ...
    or
    <select name="number[foo][]" ...
    
    <select name="number[bar][]" ...
    print_r($_POST['number']);

  5. #5
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

    But how can we differentiate list box name in the next page

    print_r($_POST['number']) gives me an array

    plz help me
    Thanks

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $select_menus $_POST['number'];
    foreach (
    $select_menus as $menu_name => $selections) {
        echo 
    "$menu_name\n";
        foreach (
    $selections as $s) {
            echo 
    "  $s\n";
        }


  7. #7
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry

    Thanks

    I have 3 buttons in my page and seprate 3 listboxes attached .when i am clicking on a particular button
    I need the that list box value in the next page.How can I solve this ?


    Actualy my form and submitt buttons are dynamic.if dynamic how can i get the value in the next page based on the user selected the particular button

    please see the attachement for details

    plz help me

    Thanks
    Attached Images Attached Images
    Last edited by aniltc; Dec 12, 2006 at 02:03. Reason: more explonation neede

  8. #8
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make 3 different forms, or name the submit buttons with names which correspond to the names of the select menus

  9. #9
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    wheher this will solve

    HTML Code:
    <form name="form1" method="post" action="select.php">
    <div align="center">
      <p>
        <select name="number[0][]" class="text" id="number[0][]" multiple >
          <option value="Select">Select</option>
          <option value="1">1</option>
          <option value="3">3</option>
          <option value="2">2</option>
          <option value="4">4</option>
        </select>
    <p>
    <p>
        <select name="number[0][]" class="text" id="number[0][]" multiple >
          <option value="Select">Select</option>
          <option value="1">1</option>
          <option value="3">3</option>
          <option value="2">2</option>
          <option value="4">4</option>
        </select>
    <p>
        <input type="submit" name="Submit1" value="Submit1">
    </p>
    </form>
    <form name="form2" method="post" action="select.php">	<select name="number[1][]" class="text" id="number[1][]" multiple >
          <option value="Select">Select</option>
          <option value="12">12</option>
          <option value="32">32</option>
          <option value="22">22</option>
          <option value="42">42</option>
        </select>
      </p>
      <p>
        <input type="submit" name="Submit2" value="Submit2">
    </p>
    </div>
    </form>
    PHP Code:
    <?php
    ini_set
    ("display_errors",0);
    $select_menus $_POST['number'];
    foreach (
    $select_menus as $menu_name => $selections) {
        
    //echo "$menu_name\n";
        
    foreach ($selections as $s) {
            echo 
    "  $s\n";
        }


    ?>


Bookmarks

Posting Permissions

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