Solved

Dynamically Create a select element with options using jquery

Posted on 2012-03-28
2
497 Views
Last Modified: 2012-04-05
Hi,

I want to create a select with multiple options using jquery.

<table id="tblForm"></table>

I want to append dropdown list to this table.

Here is my select list which I want to build dynamically using jquery.

<Select id="dynSelect">
 <option value="choice1">Choice1</option>
<option value="choice2">Choice2</option>
<option value="choice3">Choice3</option>
<option value="choice4">Choice4</option>
<option value="choice5">Choice5</option>
</Select>

Thanks for the help.
0
Comment
Question by:r_pat72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 37779850
For example : http://jsfiddle.net/6VZG9/1/
    $(document).ready(function() {
    
    var mySelectString = '<Select id="dynSelect"><option value="choice1">Choice1</option><option value="choice2">Choice2</option><option value="choice3">Choice3</option><option value="choice4">Choice4</option><option value="choice5">Choice5</option></Select>';

    $("#tblForm").html(mySelectString);
     
    })

Open in new window

¿
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 37779860
another one : http://jsfiddle.net/6VZG9/3/

    $(document).ready(function() {
    
        var mySelectString = '<Select id="dynSelect"></Select>';
    
        $("#tblForm").html(mySelectString);
        var j = [["choice1","Choice1"],["choice1","Choice1"],["choice1","Choice1"],["choice1","Choice1"],["choice1","Choice1"]];
        $.each(j, function(i,v) {
            $("#tblForm select").append("<option value='" + v[0] + "'>" + v[1] + "</option>");
        })
     
    })

Open in new window

¿
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question