SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Select Menus + JScript

    Hi all,

    I want to enable the user to add as many select menus as is required. Each select menu should be populated with data from a database table.

    The menus are created ok but I am unable to get the data into the select menus.

    Any ideas?

    PHP Code:
     $query "SELECT FFNumber, FirstName, SurName, TDATE, EmpStatus ".
             
    "FROM EMPLOYEES_Registered";
     
    $result mysql_query($query) or die(mysql_error());
     
     
    // DISPLAY LIST OF NAMES
     
    if(isset($error_message['ffnumber'])) { echo  $error_message['ffnumber']; }
     echo 
    '<p id="qs"> '.
          
    '<label for="ffnumber">Name:</label> '.
              
    '<select name="ffnumber" id="ffnumber"> '.
          
    '<option value="0">Select Name</option>';
     
     while(
    $row mysql_fetch_array($result))
     {
     / 
    SET NAME/FFNUMBER VARIABLE
     $value 
    $row['FFNumber'].'-'.$row['SurName'].'-'.$row['FirstName'];
     echo 
    '<option value= "'.$value.'">'.$row['SurName'].' '.$row['FirstName'].'</option>';
     }
                 
     echo 
    '</select> '.
         
    '<button onclick="addStaff(); return false;">Add another</button></p>';
     
    ?> 
    JavaScript:
    Code:
     <script language="JavaScript" type="text/javascript">
     <!--
     
     var fieldCount = 1;
     function addStaff() 
     {
     		fieldCount++;
     		var newStaff = document.createElement('select');
     		newStaff.name = 'ffnumber[]' + fieldCount;
     		newStaff.id = 'ffnumber' + fieldCount;
     		document.getElementById('qs').appendChild(newStaff);
     }
     
     //-->
     </script>

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any ideas guys? Tried adding a option element to the javascript but didnt work. Still unable to get the data into the select menus.

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't really understand the question, how about some sample code that doesn't include php


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
  •