I am just wondering is there a way in php to add new textfield when I click a "Add" button, for example on the form, I am not sure how many items user will enter, so I want to create a textfield with a button "Add", when user click "Add" button it will popup a new textfield.
I know is possible in javascript, however the form has a lot of data, I don't want to use "GET" method to have it listed in the url, just want to know is it possible to implement in php? thanks.
Add new textfields
Moderator: General Moderators
-
seahorse123
- Forum Newbie
- Posts: 8
- Joined: Tue Sep 20, 2005 9:06 pm
-
seahorse123
- Forum Newbie
- Posts: 8
- Joined: Tue Sep 20, 2005 9:06 pm
Sorry I am still not quite understand, for example I have code:
I can populate data into dropdown list, now if I create a new element through javascript, how to "copy" this dropdown menu when I click "add new dropdown" button? can you show me some sample code? thanks.
Code: Select all
<?
$result1=mysql_query("select id,name from table");
print "<select name=abc>";
display();
print "</select>";
print "<input type=button value="add new dropdown" onclick="createnew()">";
function display() {
for ($i = 0; $i < @mysql_num_rows( $result1 ); ++$i)
{
$line = mysql_fetch_row($result1);
print "<option value=$line[0]>$line[1]</option>";
}
}
?>
<script>
function createnew(){
var new = document.createElement("<select name=abc>")
?????
document.body.insertBefore(new);
}
</script>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
basics..........
Code: Select all
var frm = document.forms['yourFormName'];
var opts = frm.elements['originalSelectName'].options;
var sel = document.createElement('SELECT');
for(var i = 0; i < opts.length; i++)
{
sel.options[i] = new Option(opts[i].text, opts[i].value, false, opts[i].selected);
}
frm.appendChild(sel);