Jump to content

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


Giri J

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.