Welcome Guest, Not a member yet? Register   Sign In
how to generate new input fields based upon a text field value?
#1

[eluser]towki[/eluser]
Please see image.
http://i47.tinypic.com/2qdxtox.png

In my screen shot, you'll see I have created a text field asking for a number of victims and a submit button with the value "GO"(in the lower part red background). When a number of victims is entered and click the submit button "GO", on the same page(nothing will change except the addtional input fields) new input fields will be generated for each victim's data(e.g name,sex,age..) depending on the number of victims entered. So it would be like a one whole form to be submitted to the database when the "SAVE" button is clicked.

Please give me examples, if possible in php, please

Sorry for my english, I hope you got my point.

#2

[eluser]solid9[/eluser]
You need to learn jQuery for this,
http://www.mkyong.com/jquery/how-to-add-...th-jquery/

#3

[eluser]towki[/eluser]
is this not possible in Php?? I have no knowledge of javascript
#4

[eluser]solid9[/eluser]
It is possible in php.
You can just use if and else with it.
But it is easier and interactive to implement using jQuery.

Here is a good tutorial in jQuery,
http://net.tutsplus.com/articles/news/an...of-jquery/

Take the time to learn the tutorial, it is worth the time you spent learning it.
I promise you, you will not regret it.

#5

[eluser]towki[/eluser]
[quote author="solid9" date="1351321032"]You need to learn jQuery for this,
http://www.mkyong.com/jquery/how-to-add-...th-jquery/

[/quote]

I have tried to this to my code and it works fine but however when i click my SAVE button and the form doesnt send because of validation errors, the generated fields resets itself so the data which i have entered lately are gone. There is no problem in my own created fields because i managed this issue in my php code.
#6

[eluser]solid9[/eluser]
Review the manual,
http://ellislab.com/codeigniter/user-gui...latingform
#7

[eluser]Smalbach[/eluser]
is easy to do in PHP, tell me more about the form and I will help you.

What language do you speak?
#8

[eluser]towki[/eluser]
[quote author="Smalbach" date="1351392574"]is easy to do in PHP, tell me more about the form and I will help you.

What language do you speak?
[/quote]

Filipino language
#9

[eluser]towki[/eluser]
I think this example code is what i need, because its very simple just plain javascript.
But im still confused how to get the values in each field generated by this code.

Could anyone please use this code and give me an example in getting values of the generated fields then store it in a variable or insert in into the database. Please i'll try to understand.
#10

[eluser]Smalbach[/eluser]
in php
file1.php
Code:
<form action="file2.php" method="post" >

amount of fields

<!--type the amount of field that you want to display in the nest form -->

<input type="text" name="amount">
<input type="submit" value="Generate">


</form>

file2.php

Code:
<?php

//get te parameter
$amount=$_POST['amount'];

//make a cycle
echo "<form action='other_file'>";
for($i=0;$i<$amount;$i++){
?&gt;
<br>
field &lt;?php echo ($i+1) ?&gt;
&lt;input type="text" name="field_name&lt;?php echo $i ?&gt;"&gt;



&lt;?php
}

echo "&lt;/form&gt;"
?&gt;

you can integrate with codeigniter
but I recommend you to do it with jquery, is more attractive

@solounaverdad




Theme © iAndrew 2016 - Forum software by © MyBB