i'm trying to get jquery to add the value of a select box to both a hidden input field and a div to show in public view.
here's my code
<script type='text/javascript'>
$("#departments_submit").click(function(){
added_departments = new Array();
var depo = $("#depo_list").val();
alert(jQuery.inArray(depo, added_departments))
if(jQuery.inArray(depo, added_departments) != -1)
{
return false;
}
else
{
added_departments.push(depo);
}
$("#depo_added_list").append("<li>" + depo + "</li>");
var current_value = $("#departments").val();
if(current_value)
{
$("#departments").val(current_value + "," + depo);
}
else
{
$("#departments").val(depo);
}
return false;
alert(added_departments)
});
</script>
problem i'm having, is when the user submits the select form, if the item has already been added it will still add it to the field and the div when its not supposed to.
any ideas?