Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding multiple rows dynamically and persisting to database

Posted on 2013-02-06
12
Medium Priority
?
307 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
[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
  • 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
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
 
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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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…

721 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