I'm attempting to take the values from a HTML form and use JavaScript to create a multidimensional array with only selected values and then return this array as part of the returned POST values to a PHP script where it will be read out from the array into discrete records for updating.
I don't 'need' JavaScript to do this as HTML can parse multidimensional arrays and return the values that have been selected.
The reason I'm using JavaScript is that by reading the checkbox values which have been 'ticked' I can build an array with only the 'records' (each row) that will require to be edit/updated.
Using HTML/POST only, without JavaScript, the values of ALL input fields are returned and this is a waste of header space when may only one to two records out of tens will be updated on a given submit.
I have it all working...sort of... the problem I have is building the multidimensional array in JavaScript and then passing that as a multidimensional array to the HTML input value for POST to PHP.
My array does pass the values back to PHP in the POST data, however it's only in a one dimensional array as seen by PHP print_r().
I know JavaScript doesn't really support multidimensional arrays, but thought one could just add an array to an array and thus build a multidimensional array.
This is the area I'm struggling with.
Any help would be VERY much appreciated.
I have included a small test script to show what I'm attempting to do. Sorry, it's not flash and more than likely logically flaw, but hope we can look past that to provide some direction or possible answers.
My output as seen in PHP is as follows. This is when the cat and car records are selected.
I'm wondering if I have understood the inter-play of HTML text type Input and their values and the assignment of an array to that value/name.
I'm almost thinking the name attribute in the HTML input element is the array and that the value attribute is only the mechanism for assigning a value to the array.
It's as if the array assigned to the value attribute is being serialized and that I should be assigning the array to the HTML name attribute instead.
Just thinking out loud, I've never done this before and I'm not sure of the process. More testing I guess.
Bookmarks