justinbriggs1 Posted October 6, 2008 Share Posted October 6, 2008 Hello everyone, I have a question concerning javascript, php, and arrays that I thought someone might be able to help me out with.I would like to create an array from a series of input boxes with javascript, but then I need to input the array into a database using PHP. I need to know if I can use the javascript array elements in PHP. Can anyone point me in the right direction here? I have been reading up on AJAX but I'm not quite sure that is the path I need to follow. Thanks,JW Link to comment Share on other sites More sharing options...
aspnetguy Posted October 6, 2008 Share Posted October 6, 2008 You can't use javascript objects in PHP. You would have to store your array in an input field (common delimited list?) and then submit it to PHP (or via Ajax) then PHP could read the field and split it into a PHP array. Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 6, 2008 Share Posted October 6, 2008 Actually, PHP can make an array from form input elements: <input type="text" name="foo[]"><input type="text" name="foo[]"><input type="text" name="foo[]"><input type="text" name="foo[]"> All of these will be available to PHP as $_POST['foo'] (an array). You can also put the inputs in a JavaScript array (document.getElementsByName('foo[]') or via unique id attributes) to keep track of them. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.