Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamically add rows that have ddSlick image drop down

Posted on 2013-02-05
7
Medium Priority
?
2,392 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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

596 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