problem with $_POST array

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
slash_gnr3k
Forum Commoner
Posts: 43
Joined: Tue Nov 28, 2006 6:41 pm

problem with $_POST array

Post 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???
slash_gnr3k
Forum Commoner
Posts: 43
Joined: Tue Nov 28, 2006 6:41 pm

Post 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?
slash_gnr3k
Forum Commoner
Posts: 43
Joined: Tue Nov 28, 2006 6:41 pm

Post 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!
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post 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.
slash_gnr3k
Forum Commoner
Posts: 43
Joined: Tue Nov 28, 2006 6:41 pm

Post 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!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Moved to Client Side.
tamanduarj
Forum Newbie
Posts: 2
Joined: Tue Mar 20, 2007 7:33 am

Post 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
Post Reply