SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pin selected item in Listbox1 ?

    I have a form with two listboxes on it.
    Now I need to select both boxes every time for getting results.
    What I would like is that I only have to click the top listbox once and this box keeps its selected item until I selct another value in the list.

    Every item from box 1 has 4 subcategories which can be selected from box 2
    This the code for the form:
    PHP Code:
    // Start Form
    $html_form '<form action="' $_SERVER[PHP_SELF] . '" method="POST">';
      
    // Wedstrijd drop-down
      
    $html_form .= '<strong>Selecteer de Wedstrijd</strong> <br />';
      
    $html_form .= '<select name="Naam">';
      
    $html_form .= '<option selected value="">Alle Wedstrijden</option>';
      foreach (
    $wedstrijdnaam as $w_naam)
      {    
    $html_form .= '<option>' $w_naam '</option>';
      }
      
    $html_form .= '</select> ';
      
    // Second dropdown
      
    $html_form .= '<br /><br ><strong>Selecteer de Klasse <br /></strong>';
      
    $html_form .= '<select name="Klasse">';
      
    $html_form .= '<option selected value="">Klasse</option>';
      foreach (
    $Class as $g_name)
      {
          
    $html_form .= '<option>' $g_name '</option>';
      }
      
    $html_form .= '</select> ';
      
    // Search button
      
    $html_form .= '<input type="submit" name="Search" value="Bekijk" />';
      
    $html_form .= '</form></>';
      echo 
    $html_form
    Anyone ideas ? Thanks

  2. #2
    SitePoint Zealot soart's Avatar
    Join Date
    Nov 2003
    Location
    Norwich UK
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This does select from box 1 and 2 so the secondary option modifies the 1st box selection, all populated from a table

    PHP Code:
    // selected from relevant two tables
    // within form tags

                   <td height="48" class="medboldtable"> <div align="center">By 
              <select name="interestid" size ="1">
                <option selected value="">Interest</option>   <?php
       
       
    while($int=mysql_fetch_array($interest)){
       
    $interestid=$int['id'];
       
    $interesttext=htmlspecialchars($int['interesttext']);
       echo(
    "<option value='$interestid'>$interesttext</option>\n");
       }
       
    ?>
              </select>
              <br />
              And/Or</div></td>
        </tr>
        <tr> 
          <td class="medboldtable"> <div align="center">By 
              <select name="mediumid" size="1">
                <option selected value="">Medium</option>
                <?php
       
    while($med=mysql_fetch_array($medium)){
       
    $mediumid=$med['id'];
       
    $mediumdata=htmlspecialchars($med['mediumdata']);
       echo(
    "<option value='$mediumid'>$mediumdata</option>\n");
       }
       
    ?>
    virtually straight out of Kevin Yanks Book, hope it helps

  3. #3
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi soart,
    Thanks for your reply, but I'm new to PHP, I don't understand how to implement this in my code..

  4. #4
    SitePoint Zealot soart's Avatar
    Join Date
    Nov 2003
    Location
    Norwich UK
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cut down code but complete.
    Assumes database connectivity and sessions

    Tables are interest with id and interesttext as columns
    medium with id and mediumdata as columns

    ie table medium id = 1 mediumdata = DVD
    id = 2 mediumdata = Video

    table interest id = 1 interesttext = Musicals
    id = 2 interesttext = Horror

    so choosing DVD and Horror will list all titles which are both DVD and Horror in the page showresult.php

    of course the table containing the titles has to hold the interestid and mediumid which equate to the relevant id entry in the relevant tables

    PHP Code:
    <body>
    <?php
    $interest
    =mysql_query('select id, interesttext from interest order by interesttext');
    $medium=mysql_query('select id, mediumdata from medium');
    ?>

    <form action="showresult.php" method="get" target="_parent">
      <?php
            $sessid 
    strip_tags (SID);
            
    $sesssplit preg_split ("/=/"$sessid);
            
    $sessname $sesssplit[0];
            
    $sessid $sesssplit[1];
        
    ?>

        <input type="hidden" value="<?php echo $sessid ?>" name="<?php echo $sessname ?>">
     
     <table width="80%"  border="0" align="center">
        <tr> 
          <td width="37%">
              Search:<br />
            </div></td>
        </tr>
        <tr> 
          <td height="48"><div align="center">By 
              <select name="interestid" size ="1">
                <option selected value="">Interest</option>
                <?php
       
       
    while($int=mysql_fetch_array($interest)){
       
    $interestid=$int['id'];
       
    $interesttext=htmlspecialchars($int['interesttext']);
       echo(
    "<option value='$interestid'>$interesttext</option>\n");
       }
       
    ?>
              </select>
              <br />
              Or</div></td>
        </tr>
        <tr> 
          <td class="medboldtable"> <div align="center">By 
              <select name="mediumid" size="1">
                <option selected value="">Medium</option>
                <?php
       
    while($med=mysql_fetch_array($medium)){
       
    $mediumid=$med['id'];
       
    $mediumdata=htmlspecialchars($med['mediumdata']);
       echo(
    "<option value='$mediumid'>$mediumdata</option>\n");
       }
       
    ?>
              </select>
              <br />
            </div></td>
        </tr>   
        <tr> 
          <td height="26">
            <div align="center"> 
              <input type="submit" name="submit" value="Search" />
            </div></td>
        </tr>

      </table>
      </form> 

    <br /></div>

    </body>
    </html>
    hope it helps

  5. #5
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oke thanks, this makes more sense to me now :-)

  6. #6
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code posted by soart is not what I am looking for..
    Let me rephrase my question:

    I'm using a form with 2 selectboxes.
    box1 gives all the names of matches, box 2 gives 4 subcategories.(Always the same categories)
    When I've clicked box2 to select teh categorie I wish to view, the selected matchname from box1 dissappears and has to be selected again if I want to select another subcategorie..

    What I want is that box1 is keeping it first selected value until I select another matchname.
    Hope this sheds some light..

  7. #7
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this maybe?
    PHP Code:
    <?
    //form has been submitted
    //repopulate it
    $html_form .= "<select name=\"Naam\">";
    foreach (
    $wedstrijdnaam as $w_naam){
        if(
    $w_naam == $_POST['Naam']){
            
    $html_form .= "<option value=\"$w_naam\" selected=\"selected\">" $w_naam "</option>";
        }
        else{
            
    $html_form .= "<option value=\"$w_naam\">" $w_naam "</option>";
        }
    }
    $html_form .= "</select>";
    ?>

  8. #8
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks mudshark
    Going to try this..

  9. #9
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm too dumb... sorry
    Can someone help me with correting this code :
    It shows all matchnames, stays selected but gives no output..

    PHP Code:
    // Start Form
    $html_form '<form action="' $_SERVER[PHP_SELF] . '" method="POST">';
    //form has been submitted 
    //repopulate it 

      // Wedstrijd drop-down
      
    $html_form .= "<select name=\"Naam\">"
    foreach (
    $wedstrijdnaam as $w_naam){ 
        if(
    $w_naam == $_POST['Naam']){ 
            
    $html_form .= "<option value=\"$w_naam\" selected=\"selected\">" $w_naam "</option>"
        } 
        else{ 
            
    $html_form .= "<option value=\"$w_naam\">" $w_naam "</option>"
        } 

    $html_form .= "</select>"
    // Second dropdown
      
    $html_form .= '<br /><br ><strong>Selecteer de Klasse <br /></strong>';
      
    $html_form .= '<select name="Klasse">';
      
    $html_form .= '<option selected value="">Klasse</option>';
      foreach (
    $Class as $g_name)
      {
          
    $html_form .= '<option>' $g_name '</option>';
      }
      
    $html_form .= '</select> ';
      
    // Search button
      
    $html_form .= '<input type="submit" name="Search" value="Bekijk" />';
      
    $html_form .= '</form></>';
      echo 
    $html_form

    Not that dumb.. hehe figured it out, now it's doing want I want..
    Last edited by pookie62; Jan 20, 2005 at 12:30. Reason: figured it out


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
  •