First user will enter that how many textboxes he want to create.
for example he select 4 from list, then 4 textboxes will be created.
After that these, code will create textboxes dynamically in php and send its values to another php page.
kindly help to complete this task.
-
1Have you done some starting code to share with us?nanocv– nanocv2015-12-12 18:36:29 +00:00Commented Dec 12, 2015 at 18:36
-
That's the best way for us to help younanocv– nanocv2015-12-12 18:37:09 +00:00Commented Dec 12, 2015 at 18:37
-
thanks for reply ... @nanocv ...some part is solved in this link stackoverflow.com/questions/22630864/…star– star2015-12-12 18:44:24 +00:00Commented Dec 12, 2015 at 18:44
-
but it need to be customize.star– star2015-12-12 18:45:42 +00:00Commented Dec 12, 2015 at 18:45
-
Ok, give me a moment and I'll write you a code, but I think the best way to create the "textboxes" (textareas I guess) dinamically is with Javascript.nanocv– nanocv2015-12-12 18:51:13 +00:00Commented Dec 12, 2015 at 18:51
|
Show 1 more comment
1 Answer
I would do something like this.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<label for="inputTextareasNumber">How many textareas do you want?</label>
<input type="number" id="inputTextareasNumber" min="1">
<button type="button" id="butCreateTextareas">Create textareas</button>
<form id="myDynamicForm" action="myPHPfile.php" method="post"></form>
<script>
/* HTML elements caching */
var inputTextareasNumber = document.getElementById("inputTextareasNumber");
var butCreateTextareas = document.getElementById("butCreateTextareas");
var myDynamicForm = document.getElementById("myDynamicForm");
/* Create textareas when click button */
butCreateTextareas.addEventListener("click", createTextareas);
function createTextareas() {
/* First we empty the form so we can re-create it with a different number of textareas*/
emptyElement(myDynamicForm);
/* Here we get the number of textareas we want */
var textareasNumber = inputTextareasNumber.value;
/* We create and append to the form as many textareas as number we wrote in the input */
for (var i = 1; i <= textareasNumber; i++) {
var newTextarea = document.createElement("textarea");
newTextarea.name = "myTextarea" + i;
myDynamicForm.appendChild(newTextarea);
}
/* We crate and append the submit button */
var submitButton = document.createElement("input");
submitButton.type = "submit";
submitButton.value = "Send";
myDynamicForm.appendChild(submitButton);
}
/* Empty any HTML element */
function emptyElement(element) {
while (element.lastChild) {
element.removeChild(element.lastChild);
}
}
</script>
</body>
</html>
Here you have it working: jsfiddle
A very very basic PHP receiver could be this (myPHPfile.php):
<?php
foreach ($_POST as $textareaValue) {
echo "<p>$textareaValue</p>";
}
10 Comments
nanocv
Great! If you need any help with this code or with the PHP receiver just let me know
star
one more thing ... if you don't mind. kindly write code that ... How to receive theses textboxes values in another php page.
nanocv
Sure. What do you want to do with the values? Just show them on the screen?
star
Actually i am making different web pages ...on the basis of textboxes
nanocv
Ok, then the standard answer is: if you send the form with the "get" method, you will have an array variable called "$_GET" in the PHP receiver. The array will have as many positions as textareas you created.
|