Solved

Adding multiple rows dynamically and persisting to database

Posted on 2013-02-06
12
300 Views
Last Modified: 2013-02-08
A product row can be added by clicking the Add Row link.
This will add a new row with the ddSlick select.

When a user adds new rows, I need to be able to persist the values to the database.
The onSelected event fires, and now I just have an alert
alert(data.selectedData.value)

I can use the onSelected event to set the value to a hidden field, but will that cause me issues if the user adds more than 1 row?

Am I going about this the wrong way?


http://jsfiddle.net/xarPG/4/
0
Comment
Question by:JRockFL
  • 6
  • 6
12 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38863911
I can use the onSelected event to set the value to a hidden field, but will that cause me issues if the user adds more than 1 row?

Open in new window


Create an array (add [] to each hidden field's name)

<input type="hidden" name="ddSlick[]" />
<input type="hidden" name="ddSlick[]" />
<input type="hidden" name="ddSlick[]" />

on the server side you get an array for the parameter ddSlick
0
 
LVL 8

Author Comment

by:JRockFL
ID: 38865708
Thank you for the reply.

When I try to access it on the server side
Request.Form("products") = null

Request.Form("products[]") = ","

Am I doing this right?

<input type='hidden' name='products[]' id='products[]' />

$('#products').val(data.selectedData.value);
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38865953
don't use this for ID, ID atribute value MUST BE unique in a document
hope you're talking about .Net :
http://stackoverflow.com/questions/2776711/passing-array-values-in-an-http-request-in-net
0
 
LVL 8

Author Comment

by:JRockFL
ID: 38866170
I have updated the way in which the hidden field's value is set. Yes. I'm using .net

$('input[name=products]').val(data.selectedData.value);

<input type='hidden' name='products' />

Open in new window

I added two rows with two different products. When I do it this way,  there are two values but they are both the same when it should be different.

Results:
?Split(Request.Form("products"), ",")
{Length=2}
    (0): "11"
    (1): "11"

When I use this name, no values are saved.
Results:

<input type='hidden' name='products[]' />

Open in new window


?Split(Request.Form("products"), ",")
{Length=1}
    (0): ""
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38866191
Not sure where, how you put this line
$('input[name=products]').val(data.selectedData.value);
So randomly I can propose :
$(this).closest("tr").find('input[name=products]').val(data.selectedData.value);
OR :
$(this).find('input[name=products]').val(data.selectedData.value);

Please update the jsfiddle IF YOU TRIED and it don't work, thanks
0
 
LVL 8

Author Comment

by:JRockFL
ID: 38866313
Still not working.

I have update jsfiddle
http://jsfiddle.net/xarPG/10/

1. Add a new row. (The value of the id will be set to the quantity textbox to easily see value)
2. Add a second row.
3. Change the value of the second row. The first value is also updated. This is the problem.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 82

Expert Comment

by:leakim971
ID: 38866535
where did you put the code provided ID 38866191?
I can't locate it
0
 
LVL 8

Author Comment

by:JRockFL
ID: 38866570
I took it out, it was above updaterows
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38866579
please put it at the same position when you said it don't work.
0
 
LVL 8

Author Comment

by:JRockFL
ID: 38867613
I have updated fiddle, line 45.

I also changed the code to display the value in quantity textbox instead of hidden field so I could see results.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38867647
thank you
replace :
$(this).find('input[name=products]').val(data.selectedData.value);
by :
data.selectedItem.closest("tr").find('input[name=quantity]').val(data.selectedData.value);
0
 
LVL 8

Author Closing Comment

by:JRockFL
ID: 38867650
You are awesome!
That did it :)

Thank you so much for your dedicated help with this.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now