SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dropdown array validation

    i want to validate that a selection is made when the form is submitted. the tricky part is i also have an option where the user can add more rows so that they can insert more than 1 record at a time. how do i get the js to validate?

    this is my html and js notice the name of the select is 'cid[]'

    Code:
      <td bgcolor="#666666"><SELECT name='cid[]' class="one_pixel_border">
               <option selected value="">Select One</option>
                <?
    
                   $cQuery = mysql_query("SELECT cid, category FROM category");  
    
               while ($sRow = mysql_fetch_row($cQuery))
                        {
    
                                                       print ("<OPTION value='$sRow[0]'>$sRow[1]</OPTION>");
                        }
    ?>
              </SELECT> </td>
    
      <script language="javascript1.2" type="text/javascript">
    
    function valbutton(thisform)
    {
    
     
      
        if (thisform.cid.selectedIndex < 1)
      {
        alert("Please select a category.");
        thisform.cid.focus();
        return false;
      }
      
    
    }
    
    
    
    </script>

  2. #2
    Non-Member Girish singh's Avatar
    Join Date
    Jan 2011
    Location
    india,noida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By javascript we can handle drop down array list by this Funtion
    function addOption(selectbox,text,value )
    {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
    }


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
  •