m z
Posts: 0
Joined: Sat Nov 02, 2013 1:39 am

Content from input box array?

I have a list service which takes a JSON array of "questions" and "answers" from the database and populates a list item element. Inside the listitem, I use an inputbox so the user can update the answers and then update the database. The list service is working fine and the input boxes are getting populated properly.

Now, how do I get the input box contents after the user updates the fields and convert each box into a JSON array? Ultimately, the updated answers go back to the database via an update/create service.

Image

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Content from input box array?

Are you trying to refresh the inputs with the values user saved?

m z
Posts: 0
Joined: Sat Nov 02, 2013 1:39 am

Content from input box array?

I'm trying to take the inputs from the user (who is answering the questions) and then update those values in the database.

In the screen shot above, the database has the array value ["",""], so nothing gets populated in the input box. I've tested with values and the input boxes are getting populated properly once the list service completes.

Image

My goal is to take the multiple answers and update the database field. For example if answer1 = A and answer2 = B, the JSON array would be ["A","B"] and that would get updated in the database.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Content from input box array?

You are asking how to read the vales from the page and format into ["A", "B"]?

m z
Posts: 0
Joined: Sat Nov 02, 2013 1:39 am

Content from input box array?

yes. but the list is dynamic so that's why I'm having difficulty.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Content from input box array?

If the components are added to the page in runtime, you would need to traverse the DOM, find the input components and read their values.

m z
Posts: 0
Joined: Sat Nov 02, 2013 1:39 am

Content from input box array?

Thanks Max. Any good resources I could use to understand "traversing the DOM and finding the component values" or at least some good Appery examples?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Content from input box array?

Hello! If you need to traverse elements on page you have to select them and use jQuery each function http://api.jquery.com/each/
Example pre$(selector).each(function (){
var elementItem = $(this);
//---- user JS code ----
});/pre where selector - elements selector http://api.jquery.com/jQuery/#jQuery1

m z
Posts: 0
Joined: Sat Nov 02, 2013 1:39 am

Content from input box array?

Thanks for the good feedback. So I have the following code working:

$(this).children().each(function(index) {
if(index){
alert($(this).text());
// alert($(this).val());
alert(index);
}
});

My dynamic list has three elements: two labels and one input box. When I run my code I get the label text and the index but I can't get the value from the input box. Something simple I'm overlooking?

m z
Posts: 0
Joined: Sat Nov 02, 2013 1:39 am

Content from input box array?

Here's a snapshot of the html. I think since I'm using children, I'm not going down another level to get the input box values. Image

Return to “Issues”