Simple JavaScript will do the trick. The parts you need to understand:
1. the "return" keyword, and how it is used with a submit button to either perform or cancel a form submission (that is to say, if you really meant "submit" button in your question, as a normal button can do the same thing)
2. the "id" attribute... you'll need to give each HTML element a unique id, so that it can be referenced via JavaScript
3. the "document.getElementById()" method
4. how selects are referenced, their attributes and methods.
If you have a textbox and a select element in your form:
[html]
Volvo
Saab
Fiat
Audi
[/html]
Then you could add an "onChange" handler to the select:
[html]
Volvo
Saab
Fiat
Audi
[/html]
The "doSelect()" function might look like this:
[html]function mySelect(x)
{
document.getElementById("myText").value = x.options[x.selectedIndex].value;
}[/html]
Each time the user selects a new option in the select, the value of the selected option is copied to the textbox. The same technique could be done for hidden elements, and of course the function could be wired to the submit event of the form instead of the change event of the select.
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
Simply maintain a counter variable. Each time the "Add" button is clicked, it increments the counter. The "mySelect" function can use the variable to reference the proper text box(es).
function mySelect(x)
{
document.getElementById("equipment_" + myCounter).value = x.options[x.selectedIndex].value;
}
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
Define your counter outside of a function, that way it becomes a global variable which can be used by any function.
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
It's the same technique. As long as every element has a unique "id" attribute, the element can be retrieved via the document.getElementById() method. Once retrieved, its attributes, including value, can be set.
The trick is to have a rational system of providing unique ids to your dynamic elements, as well as a method of storing them and/or recreating them as needed.
Please be more careful with your terminology. There is no such thing as a "PHP Form" (or "fields" in HTML, for that matter), so I cannot provide quality help without resorting to guesswork as to what you really mean.
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
I understand. This has turned into a PHP question. You want to process the results of a form submission, and author a new page, populating the new page's form with the results from the previous form.
I suggest you ask a question about getting values from the Response object in the PHP forum. In short, PHP automatically creates an associative array named $_GET in which it stores all your query string values.
To create a textbox element that is populated with a value from a previous GET might look like this:
[php]
[/php]
That assumes you've built a URL with ?textbox1=somevalue as a query string.
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
You are completely wrong. :)
PHP won't know or care how an HTML element was created, or how it got its value. As long as the element is part of a form with a proper action tag pointing to the PHP page, it makes no difference at all how the element was created or populated.
Also, an element that is submitted as a form isn't a GET request, it's a POST reqest. Perhaps that is your problem, looking for the values in GET, rather than POST.
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37