?
Solved

Dynamically add rows that have ddSlick image drop down

Posted on 2013-02-05
7
Medium Priority
?
2,343 Views
Last Modified: 2013-02-06
The AddRow will add new rows to the table, however only the first row that is added has the ddSlick custom select applied correctly.

If the AddRow link is clicked more than once, it will still add a new row, however there is is nothing for the ddSlick.

Here is the html, Please see attached screen shot.
Any suggestions?

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="ctl00_Head1"><title>
      Administration Area
</title><link rel="stylesheet" href="/Stylesheets/screen.css" type="text/css" media="screen" title="no title" charset="utf-8" /><link rel="stylesheet" href="/Stylesheets/plugin.css" type="text/css" media="screen" title="no title" charset="utf-8" /><link rel="stylesheet" href="/Stylesheets/custom.css" type="text/css" media="screen" title="no title" charset="utf-8" />
    <style type="text/css" media="screen">
       
    </style>
    <link href="/Stylesheets/smoothness/jquery-ui-1.8.13.custom.css" rel="stylesheet" type="text/css" />

   
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="/Scripts/slate/slate.js"></script>
    <script type="text/javascript" src="/Scripts/slate/slate.portlet.js"></script>
    <script type="text/javascript" src="/Scripts/plugin.js"></script>
    <script src="/Scripts/slate/slate.js" type="text/javascript"></script>
    <script src="/Scripts/jquery/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>    
    <script type="text/javascript" src="/Scripts/jquery.MultiFile.js"></script>
    <script src="/Scripts/jquery.ddslick.min.js" type="text/javascript"></script>

   
    <script type="text/javascript">
    $(document).ready(function () {
//        $('.AddRow').click(function () {
//            $('#tblProducts > tbody:last').append("<tr><td><div class='field'><select><option>Hello World</option></select></div></td><td><div class='field'><input type='text' /></div></td><td><div class='field'><input type='text' /></div></td><td><div class='field'><input type='text' /></div></td></tr>");            
//        });
    });
</script>


</head>
<body>

                <table cellpadding="0" cellspacing="0" border="0" class="display" id="tblProducts">
                    <thead>
                        <tr>
                            <th>
                                Product
                            </th>
                            <th>
                                Quantity
                            </th>
                            <th>
                                Price
                            </th>
                            <th>
                                Total
                            </th>
                            <th>
                                Shipped
                            </th>
                            <th>&nbsp;</th>
                        </tr>
                    </thead>
                    <tbody>
                       
                                <tr id="1">
                                <input name="linekey" type="hidden" value='441' class="delete-key" />  
                               <input type="hidden" name="ctl00$ContentPlaceHolder1$rpProducts$ctl00$hfSelectedProductID" id="ctl00_ContentPlaceHolder1_rpProducts_ctl00_hfSelectedProductID" value="5" />                              
                                    <td>
                                        <div class="field">
                                            <div id="productDropDown0"></div>                                                                                                                                    
                                        </div>
                                    </td>
                                    <td>
                                        <div class="field">
                                            <input name="ctl00$ContentPlaceHolder1$rpProducts$ctl00$txtQuantity" type="text" value="1" id="ctl00_ContentPlaceHolder1_rpProducts_ctl00_txtQuantity" />                                            
                                        </div>
                                    </td>
                                    <td>
                                        <div class="field">
                                            <input name="ctl00$ContentPlaceHolder1$rpProducts$ctl00$txtPrice" type="text" value="20.95" id="ctl00_ContentPlaceHolder1_rpProducts_ctl00_txtPrice" />                                          
                                        </div>
                                    </td>
                                    <td>
                                        <div class="field">
                                           <input name="ctl00$ContentPlaceHolder1$rpProducts$ctl00$txtLineTotal" type="text" value="20.95" readonly="readonly" id="ctl00_ContentPlaceHolder1_rpProducts_ctl00_txtLineTotal" />
                                        </div>
                                    </td>
                                    <td>
                                        <div class="field">
                                            <select name="ctl00$ContentPlaceHolder1$rpProducts$ctl00$ddlShipped" id="ctl00_ContentPlaceHolder1_rpProducts_ctl00_ddlShipped">
      <option value="1">Yes</option>
      <option selected="selected" value="0">No</option>

</select>                                                                                                                                    
                                        </div>
                                    </td>
                                    <td>
                                        <div class="field">
                                            <a class="AddRow">Add Row</a>
                                           
                                            <a class="DeleteRow">Delete Row</a>
                                        </div>
                                    </td>
                                </tr>
                           
 
                           
                    </tbody>
                </table>
 
   
<script type="text/javascript">
$(document).ready(function () {
var ddData = [
    {
        text: "Facebook",
        value: 1,
        selected: false,
        description: "Description with Facebook",
        imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
    },
    {
        text: "Twitter",
        value: 2,
        selected: false,
        description: "Description with Twitter",
        imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
    },
    {
        text: "LinkedIn",
        value: 3,
        selected: true,
        description: "Description with LinkedIn",
        imageSrc: "http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png"
    },
    {
        text: "Foursquare",
        value: 4,
        selected: false,
        description: "Description with Foursquare",
        imageSrc: "http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png"
    }
];
$('.AddRow').click(function () { $('#tblProducts > tbody:last').append("<tr><td><div class='field'><div id='myDropdown'></div></div></td><td><div class='field'><input type='text' id='quantity' name='quantity' /></div></td><td><div class='field'><input id='price' type='text' name='price' /></div></td><td><div class='field'><input type='text' id='linetotal' name='linetotal' readonly='readonly' /></div></td><td><div class='field'><asp:DropDownList ID='ddlShipped' runat='server'><select id='shipped' name='shipped'><option value='1'>Yes</option><option selected='selected' value='0'>No</option></select></div></td><td><div class='field'><a class='DeleteRow'>Delete Row</a></div></td></tr> ");
$('#myDropdown').ddslick({ data: ddData, defaultSelectedIndex: 0, width: 400, selectText: "Select a product", imagePosition: "left", onSelected: function (data) {} });
updateRows();}); });
</script></form>
</body>
</html>
screenshot.jpg
0
Comment
Question by:JRockFL
[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
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38857728
please put your code inside the code snippet (selet/surlign the whole code using the mouse and click on the lin code)
and what is updateRows function?
0
 
LVL 8

Author Comment

by:JRockFL
ID: 38857737
Is this what you mean?
I have included updateRows
<script type="text/javascript">
$(document).ready(function () {
var ddData = [
    {
        text: "Facebook",
        value: 1,
        selected: false,
        description: "Description with Facebook",
        imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
    },
    {
        text: "Twitter",
        value: 2,
        selected: false,
        description: "Description with Twitter",
        imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
    },
    {
        text: "LinkedIn",
        value: 3,
        selected: true,
        description: "Description with LinkedIn",
        imageSrc: "http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png"
    },
    {
        text: "Foursquare",
        value: 4,
        selected: false,
        description: "Description with Foursquare",
        imageSrc: "http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png"
    }
];
$('.AddRow').click(function () { $('#tblProducts > tbody:last').append("<tr><td><div class='field'><div id='myDropdown'></div></div></td><td><div class='field'><input type='text' id='quantity' name='quantity' /></div></td><td><div class='field'><input id='price' type='text' name='price' /></div></td><td><div class='field'><input type='text' id='linetotal' name='linetotal' readonly='readonly' /></div></td><td><div class='field'><asp:DropDownList ID='ddlShipped' runat='server'><select id='shipped' name='shipped'><option value='1'>Yes</option><option selected='selected' value='0'>No</option></select></div></td><td><div class='field'><a class='DeleteRow'>Delete Row</a></div></td></tr> ");
$('#myDropdown').ddslick({ data: ddData, defaultSelectedIndex: 0, width: 400, selectText: "Select a product", imagePosition: "left", onSelected: function (data) {} });
updateRows();}); });

    function updateRows() {
        $('table tr:even').addClass('even');
        $('table tr:odd').addClass('odd');
    }

</script>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 38857759
this is totally useless in a browser : <asp:DropDownList
This tag is for server side running .net...

anyway check this test page : http://jsfiddle.net/xarPG/2/
using :
    $('.AddRow').click(function () {
        var newRow = $("<tr><td><div class='field'><div class='myDropdown'></div></div></td><td><div class='field'><input type='text' id='quantity' name='quantity' /></div></td><td><div class='field'><input id='price' type='text' name='price' /></div></td><td><div class='field'><input type='text' id='linetotal' name='linetotal' readonly='readonly' /></div></td><td><div class='field'><asp:DropDownList ID='ddlShipped' runat='server'><select id='shipped' name='shipped'><option value='1'>Yes</option><option selected='selected' value='0'>No</option></select></div></td><td><div class='field'><a class='DeleteRow'>Delete Row</a></div></td></tr>");
        $('#tblProducts > tbody:last').append(newRow);
        $('.myDropdown', newRow).ddslick({ data: ddData, defaultSelectedIndex: 0, width: 400, selectText: "Select a product", imagePosition: "left", onSelected: function (data) {} }); 
        updateRows();
    });

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Author Comment

by:JRockFL
ID: 38857844
Yes, that is correct about the asp:dropdownlist, I overlooked that and just copied what was in the aspx page.

Your solution is working.
What did you do differently?
I see you created a variable called newRow and assigned the value.
Then you called the append method and pass in newRow.

Is there anything else that you did?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38857852
Use a class (.) instead an id (#)
0
 
LVL 8

Author Comment

by:JRockFL
ID: 38857912
Ahhh, got it. That makes sense now.
0
 
LVL 8

Author Comment

by:JRockFL
ID: 38860919
Are you still around? I'm going to post another question similar to this.
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 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