Link to home
Start Free TrialLog in
Avatar of JRockFL
JRockFLFlag for United States of America

asked on

Adding multiple rows dynamically and persisting to database

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/
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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
Avatar of JRockFL

ASKER

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);
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
Avatar of JRockFL

ASKER

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): ""
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
Avatar of JRockFL

ASKER

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.
where did you put the code provided ID 38866191?
I can't locate it
Avatar of JRockFL

ASKER

I took it out, it was above updaterows
please put it at the same position when you said it don't work.
Avatar of JRockFL

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JRockFL

ASKER

You are awesome!
That did it :)

Thank you so much for your dedicated help with this.