Ok, i have been searching for 2-3 weeks now so I apologize if this has already been answered AND I apologize if I don't get the terminology exactly right. I'm a newbie.
I am creating a budgeting program to help me learn coding. I have 3 columns in an HTML table, and an obj with key/value pairs.
I would like to use the keys in the obj to create classes for my inputs so I can send them all to a database to track/add/do whatever...
var obj = { item1=10, item2=20, item3=30}
var getkey = Object.keys(obj)
Here is one of the many loops I have tried.
for (var i = 0; i < getkey.length, i++) {
var key = getkey[i]
var keyclass = key + "id"
var appendage = "<input id='" + key + "id'" + "name='" + key + "spendinput' type='text' />"
if (i == 0) {
$("#firstrow td:nth-child(3)").append(appendage).addClass(keyclass).removeClass("spendinput")
} else if ($(".spendinput").hasClass(prevkeyclass) == false) {
$(".spendinput").append(appendage).addclass(keyclass)
}
/*Here is my HTML*/
<form method="POST" action="expense.php">
<table>
<thead>Current Budget</thead>
<tbody>
<tr id="firstrow">
<td id="utilities"></td>
<td id="utilitiestotspend" class="spendinput"></td>
</tr>
<tr>
<td id="gas"></td>
<td id="gastotspend" class = "spendinput"></td>
</tr>
</tbody>
</table>
</form>
Thank you for any suggestions.
var obj = { item1=10, item2=20, item3=30}. You sould set the pair key value with:likevar obj = { item1:10, item2:20, item3:30}