tags:

views:

49

answers:

1

Hi,

 I am using JQuery and cakephp for my application.

I have created a select input Element using

     $(document).ready(function(){
          $("#"+<?=$r['Attribute']['id'];?>).each(function() { 
          type= "<?=$r['Attribute']['type'];?>";
          attribute_id= "<?=$r['Attribute']['id'];?>";
                     if(type=="dropdown")
                     {
                     var ht = $.ajax({
                               type: "GET",
                               url: "http://localhost/FormBuilder/index.php/forms/viewChoices/" 
                               + attribute_id,
                               async: false
                           }).responseText;
                         var myObject = eval('(' + ht + ')');

         var data = myObject;var j=0;
         $.map(data.choices, function(i){ j++; alert(i.choice);
         $('<option value='+i.choice+'>'+i.choice+'</option>')
              .appendTo("#"+<?=$r['Attribute']['id'];?>);
           return i.choice;});  
            }
        });          
   });

And the one that created is like,,

   <select id="10" name="Experience">
      <option value="Fresher">Fresher</option>
      <option yrs="" 5="" value="Below">Below 5 Yrs</option>
      <option yrs="" 10="" value="Above">Above 10 yrs</option>
   </select>

I dont know why the value is not set like

       <option value="Below 5 Yrs">Below 5 Yrs</option>

Please suggest me... I know there is some problem in quotes and i tried with many options ...

+2  A: 

You should create it with

$('<option value="'+i.choice+'">'+i.choice+'</option>')

Because when you do it the first way, it returns the HTML:

<option value=Below 5 Yrs>Below 5 Yrs</option>

And the browser sees it as

<option yrs="" 5="" value="Below">Below 5 Yrs</option>
MiffTheFox