Solarpitch Posted May 26, 2011 Share Posted May 26, 2011 Hey, I'm looking to see whats the best way of submitting an array of textareas and passing the array via an Ajax request. Basically, I could have a form with 2,4,6 whatever amount of textareas, it's dynamic. When I submit the form I want to get all the values of the textareas and pass through an Ajax request. Here's where I'm at. // This is a snippet of the code I use, I do a str_replace and put in textareas, but that bits not important $replacements[3] = ' <!--SYSTEM--> <textarea name="free[]" id="free[]" ></textarea> <textarea name="free[]" id="free[]" ></textarea> <!--ENDSYSTEM--> '; // Then my Ajax $(function() { $(".save_newsletter").click(function() { var id = $(this).attr("id"); // I'm stuck here with how I get the array of textarea values and pass to Ajax below. var dataString = 'reply_content='+ val +'&title=' + title; $.ajax({ type: "POST", url: "<?php echo site_url(); ?>newsletter/save_newsletter/"+id, cache: false, data: dataString, success: function(html){ $('#message').append("Saved!"); } }); return false; }); }); Link to comment https://forums.phpfreaks.com/topic/237567-php-ajax-fun-with-textareas/ Share on other sites More sharing options...
requinix Posted May 26, 2011 Share Posted May 26, 2011 form.serialize() maybe? Separately: IDs are meant to be unique. It doesn't look like your textareas need them so just drop them. Otherwise, come up with a unique value for each textarea created. Link to comment https://forums.phpfreaks.com/topic/237567-php-ajax-fun-with-textareas/#findComment-1220816 Share on other sites More sharing options...
xyph Posted May 26, 2011 Share Posted May 26, 2011 So this is a JavaScript issue and not a PHP one? Link to comment https://forums.phpfreaks.com/topic/237567-php-ajax-fun-with-textareas/#findComment-1220817 Share on other sites More sharing options...
requinix Posted May 26, 2011 Share Posted May 26, 2011 You're having problems getting the values to PHP, right? It's not a PHP problem if PHP isn't involved. Link to comment https://forums.phpfreaks.com/topic/237567-php-ajax-fun-with-textareas/#findComment-1220818 Share on other sites More sharing options...
Solarpitch Posted May 26, 2011 Author Share Posted May 26, 2011 You're having problems getting the values to PHP, right? It's not a PHP problem if PHP isn't involved. Correct! .. Each textarea will need to have it's own id but will need to be dynamic in some way. Umm.. I'm gonna play with something here see if I can get this working Link to comment https://forums.phpfreaks.com/topic/237567-php-ajax-fun-with-textareas/#findComment-1220844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.