0

i have a jquery array which contains html code for generating checkboxes dyanmically.here is the contents of my jquery array and the name of my array is output

<input type="checkbox"   id="Mumbai" name="Mumbai" value="Mumbai" />Mumbai<br />,
<input type="checkbox"   id=" Delhi" name=" Delhi" value=" Delhi" /> Delhi<br />,
<input type="checkbox"   id=" Bangalore" name=" Bangalore" value=" Bangalore" />Bangalore<br />

Now as per my need i want to add this array called output into jquery dialogue box contained in html form ..

Here is my code..

var $dialog = $('<div></div>')
        .html('<form id="myform" action="">output</form>')
        .dialog({
            autoOpen: false,
            title: 'Select Sites',
            buttons: {
                "Submit": function() {  $('form#myform').submit();},
                "Cancel": function() {$(this).dialog("close");}
            }
        });

I have to add the array called output in the .html form which i have added like this shown in code but its not showing checkoxes instead it is showing output in the alert box message ..

Any help will be highly appreciated.. Thanks in advance..

vimal
  • 3
  • 3

3 Answers3

0

You will have to separate the html into two different parts. For example,

.html('<form id="myform" action="">' + output + '</form>')
Sachin Gaur
  • 12,909
  • 9
  • 33
  • 38
0

Try this,

var $dialog = $('<div></div>')
    .html('<form id="myform" action="">'+$('input:checkbox').clone()+'</form>')
    .....
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
0

Try this

$(window).load(function() {
        $.ajax({
            type: 'GET',
            url: 'Sites',
            success: function(data) {
                var city=data.city
                for(var i in city)
                {
                   var output='<input type="checkbox"   id="'+city[i]+'" name="'+city[i]+'" value="'+city[i]+'" />'+city[i]+'<br />'
                }
                consoloe.log(output)
            }
        });
    });

Refer this How to have jQueryUI dialog box dynamically load content

Community
  • 1
  • 1
Sridhar R
  • 20,190
  • 6
  • 38
  • 35