how to prevent duplicated entries in javascript?
<p>i have a problem in preventing duplicates from being entered, i'm generated radio buttons dynamically in 2 pages at the same time using exactly one button, i take the label from the user and generate a radio button from that label, i want to prevent the user from entering 2 identical labels, here's the script which generates radios for the 2 pages any help will be appreciated </p>

<pre><code>function createRadioElement(elem, label, checked) {
var id = 'option1_' + label;
$('#after').append($('&lt;input /&gt;', {
    'type': 'radio',
    'fieldset':'group',
    'name': 'option1',
    'id': id,
    'data-role': 'controlgroup',
    'data-theme':'b',
    'value': '1'}));
$('#after').append('&lt;label for="' + id + '"&gt;'+ label + '&lt;/label&gt;').trigger('create');}

function createRadioFortSecondPage(elem, label, checked) {
var id = 'option1_' + label;
$('#Inserthere').append($('&lt;input /&gt;', {
    'type': 'radio',
    'fieldset':'group',
    'name': 'option1',
    'id': id,
    'data-role': 'controlgroup',
    'data-theme':'b',
    'value': '1'}));
$('#Inserthere').append('&lt;label for="' + id + '"&gt;'+ label + '&lt;/label&gt;').trigger('create');}
</code></pre>

<p>that's the function i wrote to prevent duplicates:</p>

<pre><code>function checkDublicates(){
     var isExist=true;
     var x = document.getElementById('option').value;
     var labels = [];   
$('#after input[type=radio]').each(function() {
     labels.push($('label[for='+$(this).attr('id')+']').text());


    });
    for(var i=0;i&lt;labels.length;i++){

    if(x==labels[i])
    {
        isExist=false;}
        else{
        isExist=true;}
      }
    return isExist;}
</code></pre>

<p>and that's the button action:</p>

<pre><code>$('#AddButton').click(function(){
     var exist=checkDublicates();
     &lt;!--var isEmpty=validate();--&gt;
    &lt;!--if(exist==true){
        &lt;!--alert("Duplicates Are Not Allowed!");
        &lt;!--}else{
    var y=document.getElementById('question').value
    document.getElementById('headTitle').innerHTML=y;
    if(exist==false){
        alert("Duplicates Not Allowed!")
    }else{
    createRadioElement(this,$('#option').val(),true);
    createRadioFortSecondPage(this,$('#option').val(),true);
  }

  });
</code></pre>
