simeonC Posted December 1, 2013 Share Posted December 1, 2013 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); } /////////////////////////////////// } Link to comment https://forums.phpfreaks.com/topic/284423-javascript-object/ Share on other sites More sharing options...
Ch0cu3r Posted December 1, 2013 Share Posted December 1, 2013 Try customer_information[field] = value; Link to comment https://forums.phpfreaks.com/topic/284423-javascript-object/#findComment-1460851 Share on other sites More sharing options...
simeonC Posted December 2, 2013 Author Share Posted December 2, 2013 does not work Link to comment https://forums.phpfreaks.com/topic/284423-javascript-object/#findComment-1460902 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/ Link to comment https://forums.phpfreaks.com/topic/284423-javascript-object/#findComment-1460905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.