Page 1 of 1

problem with $_POST array

Posted: Thu Mar 15, 2007 9:45 am
by slash_gnr3k
i have the following javascript:

Code: Select all

<script language="JavaScript">

		var iteration = 0;

		function AddToIngList (form, iteration)
		{

			var it = iteration;

			var Ingredient = form.ingredienttoadd.value;
			form.ingredients_added.value += Ingredient + "\n";

			var objHTML, objText, objinput;

			objHTML = document.createElement('P');

			objHTML.setAttribute('NAME', 'txtTest');
			objHTML.setAttribute('ID', 'txtTest');
   
			var strTest = form.ingredienttoadd.value;
  			objText = document.createTextNode(strTest);

			objinput = document.createElement
('INPUT');
		
			objinput.name = "input"+it;
			objinput.value = "";

			document.body.appendChild(objHTML);
		
			objHTML.appendChild(objText);
			objHTML.appendChild(objinput);

			alert(objinput.name);
		
		}

	</script>
which is called on click of

Code: Select all

onClick=\"iteration ++;	AddToIngList(this.form, iteration);\">";
this works fine and basically what it does is adds the text of what ever has been selected from a drop down box (form.ingredienttoadd.value;) to the end of the page and next to that adds an input box called "input1" and the next one called "input2" etc....

the problem is this. It seems that the value from the input boxes are not goin into the $_POST array.

Code: Select all

				$test = $_POST['input1'];

					echo"<p><b>$test</b></p>";
none of the above code appears.

can anyone help me???

Posted: Thu Mar 15, 2007 10:38 am
by slash_gnr3k
ok ive used firebug to do a little more invetigating and it turns out that the input box is not actualy part of the form when created. can anyone help me with how to make it so it is?

Posted: Thu Mar 15, 2007 10:39 am
by slash_gnr3k
slash_gnr3k wrote:ok ive used firebug to do a little more invetigating and it turns out that the input box is not actualy part of the form when created. can anyone help me with how to make it so it is?
EDIT: I supposed now that i know this is a javascript problem this thread should be moved to the javascript part of the forum!

Posted: Thu Mar 15, 2007 10:39 am
by mentor
1. Did you define <form> in the page?
2. Did this element add within the scope for <form>?
3. Try debugging the post data buy using

Code: Select all

echo "<pre>";
print_r($_POST);
This will display all the posted data.

Posted: Thu Mar 15, 2007 10:52 am
by slash_gnr3k
sorted it thanks! turns out it was a javascript DOM problem. i wasnt appending the new field to the form. just the document. thanks anyway!

Posted: Thu Mar 15, 2007 2:34 pm
by RobertGonzalez
Moved to Client Side.

Posted: Tue Mar 20, 2007 7:51 am
by tamanduarj
Hi I'm having the same kind of problem. Input fields created using DOM does not show at $_POST. Please could you explain more what it means by ppending the new field to the form ?? best regard