well i am creating a registration form . the problem i am facing is
i want to generate the name text field based on the input of number of participants.

if some one wants to perform bulk registration, then he can keep filling the form again and again,
having all the details common apart from name , is there any way that i can generate a particiluar text field , mainly (the name) again based on the input of no of participants ..?

Recommended Answers

All 10 Replies

It sounds as if you need to keep all of the other details in Session variables based on what they entered the first time. Once you have processed one registration, you can either display the whole form with all of the fields pre-filled except for name (by assigning the values based on the Session values) or just display a simplified form for the name but use the Session values to fill all the other fields in the database.

well yes ,
i framed it like this

1.No of participants
2.Mode of payment

1.Name (it will generate according to no of participants)

other details.

Is there any idea on how to do it..?

I don't understand the question. Coding it is straightforward PHP and HTML. There is no mystery to it.

well its pretty simple
1. i am creating 2 forms
2.the second form (form2) will be generated based on the data entered by the user in the first form(form1).

3.The form one has 2 fields.
1.No of participants
2.Mode of payments

4.The form 2 has many fields in it, but the NAME field will be generated according to the data entered in form1 (no of participants).
The other fields will be same.



No of participants : 5
payment : Cash

Form 2

Enter name :
Enter name:
Enter name:
Enter name:
Enter name:

-----other details ---------

This is wat i wanted to do.

This is simple.

in your HTML

do this

<div id="form1">
<input id="participants">Participants
<input id="payment">Payment
<div id="form2">

<script language="javascript" type="text/javascript">
function getHTTPObject(){
      if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
      else if (window.XMLHttpRequest) return new XMLHttpRequest();
      else {
      alert("Your browser does not support AJAX.");
      return null;

function doForm2()
	httpObject = getHTTPObject();

    if (httpObject != null) {
		httpObject.open("GET", "form2.php?participants=" + document.getElementById(participants).value, true);
      	httpObject.onreadystatechange = function() { setForm2(); }

function setForm2(){
      if(httpObject.readyState == 4){

      document.getElementById('form2').innerHTML = httpObject.responseText;




Save this as whatever you want (form1.html?) and obviously fill out the input fields at the top however you want them to look.

Now create the form2.php

$i = 1;
$returncode = "<table>";
while($i <= $_GET['participants'])
    $returncode .= getNumbers();
$returncode .= "</table>";
echo $returncode;

function getNumbers()
     $code = "<tr><td>Enter Name : </td><td><input size=10></td></tr>";
     return $code;

These two parts to the program allow you to do anything within a screen. form1.html is the program that does the display. AJAX and Javascript provide the client side processing by using the form2.php program. You can have any HTML code just use $code=" you can then put HTML code here but only between the inverted commas ";

any problems give me a shout and if something doesn't work check that I haven't spelt something incorrectly.

I forgot to increment the $i in the while loop so make sure that you do this otherwise it will always be looping

Sorry I also forgot

<input id="payment">Payment

should be

<input id="payment" onBlur="doForm2();">Payment etc........

This means that when focus is lost from this input field there is a call to the Javascript to run the PHP program to generate the next form

just apply check before going to next page if your requirements are done then go ahead other wise fill the first form accurately.

noelthefish kudos to you to come up with this in such short span.

but i want to ask few questions
1.which all technologies should i use in order to do such dynamic form generation, i am a complete neophyte in PHP too.

I normally use
PHP, HTML and Javascript. You can do almost anything with these as I use the PHP file to create new tables, DIVs and infact in some cases whole new web pages.

More and more people are now using jQuery which does the same but I prefer my methods as I am still learning jQuery.

At the end of the day it is just personal preference and what you feel comfortable with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.