BernardoLima
BernardoLima

Reputation: 1141

Is there any good practice alternative to global variable in this case?

enter image description here It's an address register, that I use javascript to dynamically populate a HTML table with the inputs content.
I don't want it to insert into the database until she had filled as many addresses as she want, so it's basically adding the input values to the table.

enter image description here The problem is, I need to pass these values as an array of addresses, to insert them on my database.

I don't think parsing the table to get data would be efficient or a good approach, would global variable be a bad thing in this case?

If you have any better ideas to solve this, please share.

Upvotes: 1

Views: 49

Answers (1)

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114417

You should make a JSON-based representation of your dataset and update it along with your DOM table. Then you send the JSON object to the server via AJAX.

This is not really a "global variable" issue.

There are plenty of frameworks to help you with this if you don't want to roll-your-own: Backbone, Angular, Ember, etc.

Upvotes: 2

Related Questions