simeonC Posted December 1, 2013 Share Posted December 1, 2013 (edited) Just a question can i dynamically set javascript object key:value properties? function insert_current() { var customer_information = new Object(); //the object which my input form values will be held a = document.getElementsByTagName("input"); // gather input tags here /////////////////////////////////// loop through each to get the elements ("input") form name attribute as well as the value. for (i=0; a.length > i; i++){ field = a[i].getAttribute("name"); value = a[i].value; customer_information.field= value;//this doesn't work var x=document.getElementById("left"); x.innerHTML = JSON.stringify(customer_information); } /////////////////////////////////// } Edited December 1, 2013 by simeonC Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 1, 2013 Share Posted December 1, 2013 Try customer_information[field] = value; Quote Link to comment Share on other sites More sharing options...
simeonC Posted December 2, 2013 Author Share Posted December 2, 2013 does not work Quote Link to comment Share on other sites More sharing options...
.josh Posted December 2, 2013 Share Posted December 2, 2013 It works fine with Ch0cu3r's fix: http://jsfiddle.net/pDHZ6/1/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.