Firemankurt Posted January 27, 2011 Share Posted January 27, 2011 I am a PHP guy struggling with JS. I dynamically create forms with several fields that can change names at any time. I need to gather all form input names and values into a string that I can then send in one $_GET element? I will separate them out again in the PHP that receives the $_GET element. Here is the section of my code giving me trouble. I simplified to reduce the possibility of masking one problem with another. <html> <head> <title>FD Manual</title> <script src="http://train.iaff106.org/js/scriptaculous/prototype.js" type="text/javascript"></script> <script src="http://train.iaff106.org/js/scriptaculous/scriptaculous.js" type="text/javascript"></script> <script type="text/javascript"> NewSlidePreviewRequest = function (typeid) { var newdata = $('S').serialize(true); alert(newdata); var jsonstr= JSON.stringify(newdata); alert(jsonstr); // AJAX stuff sends string to PHP receiver for parsing and response } </script> </head> <body> <form id="S"> <label for="ImgTopCaption">Image Top Caption</label> <input type="text" id="ImgTopCaption" value="Image Top Caption"> <label for="Text">Text</label> <textarea id="Text">This is my text</textarea> <a href="#" onclick="NewSlidePreviewRequest(1)" >Click HERE</a> </form> </body> </html> I was expecting one of those alerts to contain a string like: {ImgTopCaption: 'Image Top Caption', Text: 'This is my text'} But not working like I hoped. Link to comment https://forums.phpfreaks.com/topic/225902-form-elements-into-string-with-prototype-js/ Share on other sites More sharing options...
Firemankurt Posted January 28, 2011 Author Share Posted January 28, 2011 Solved it... I had ids in form elements but not names..... Duhhhhh... Link to comment https://forums.phpfreaks.com/topic/225902-form-elements-into-string-with-prototype-js/#findComment-1166390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.