Jump to content

PHP & AJAX, Fun With Textareas..


Solarpitch

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.