
Untitled
By: a guest on
May 22nd, 2012 | syntax:
None | size: 0.68 KB | hits: 12 | expires: Never
Update form select (dropdown) from static input field
<input type="text" id="region-txt" name="region-txt" />
<select id="region" name="region">
<option value="1">Test1</option>
<option value="2">Test2</option>
</select>
$('#input').keyup(function(){
var selected = $(this).text();
$('#region').val(selected);
});
$('#input').keyup(function(){
var selected = $(this).text();
if($('#region option[value='+selected+']').length){
//item already exists
}
else {
$('#region').append(
$('<option></option>').val(selected).html("Test"+selected)
);
}
});