Jump to content

[SOLVED] I'm unable to get the values from the html form to php... Please Help


Recommended Posts

Hi,

 

I have a html + javascript code like this :

 

<html>

<head>

<title>Dynamic Form test pge</title>

<script language="javascript">

function changeIt()

{

var i = 1;

my_div.innerHTML = my_div.innerHTML +"<br><input type='text' name='mytext'+ i><br/>"

}

</script>

</head>

<body>

<form action="test-js-php.php" method="post">

<input type="button" value="test" onClick="changeIt()">

<input type="submit" value="submit">

<div id="my_div">

</div>

</body>

 

If you save this as a html file and click on test button it will keep adding the text fields.

 

Now, This is my problem:

 

> I want to enter some data into those text fields

 

> and When I submit it I want the data from the HTML form to my PHP.

 

 

My php code is like this:

 

<?php

 

$t1=$_POST['mytext1'];

$t2=$_POST['mytext2'];

$t3=$_POST['mytext3'];

 

echo $t1.$t2.$t3;

 

?>

 

Please help me. I'm not that good at Javascript.

 

 

 

change your js code  and close form tag

<html>
<head>
<title>Dynamic Form test pge</title>
<script language="javascript">
var i = 0;
function changeIt()
   {
      i = i+1;
      my_div.innerHTML = my_div.innerHTML+"<br><input type='text' name='mytext"+i+"'><br/>"
   }
</script>
</head>
<body>
<form action="test-js-php.php" method="post">
<input type="button" value="test" onClick="changeIt()">
<input type="submit" value="submit">
<div id="my_div">
</div>
</form>
</body>

Thanks a lot mate. It solved my problem :) :)

 

I'm successfully able to get the data from the dynamically generated text fields  ;)

 

Much Appreciated.

 

One final request: is there a site where we can quickly brush up JS skills with some good examples? Please let me know.

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.