Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.68 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Update form select (dropdown) from static input field
  2. <input type="text" id="region-txt" name="region-txt" />
  3.        
  4. <select id="region" name="region">
  5.   <option value="1">Test1</option>
  6.   <option value="2">Test2</option>
  7. </select>
  8.        
  9. $('#input').keyup(function(){
  10.  
  11.     var selected = $(this).text();
  12.  
  13.     $('#region').val(selected);
  14.  
  15.     });
  16.        
  17. $('#input').keyup(function(){
  18.  
  19.         var selected = $(this).text();
  20.  
  21.         if($('#region option[value='+selected+']').length){
  22.             //item already exists
  23.         }
  24.         else {
  25.              $('#region').append(
  26.                    $('<option></option>').val(selected).html("Test"+selected)
  27.              );
  28.         }
  29.  
  30.         });