user1653850
user1653850

Reputation: 29

Click add to insert another input field in php

I need to add another input field of type select if someone clicks add location as seen in my code

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <p><strong> location</strong></p></br />
<select name="location">
    <option value="location1">location1</option>
    <option value="location2">location2</option>
    <option value="location3">location3</option>
    <option value="location4">location4</option>
</select>
<a href="#" id="#newField">Add location</a>
<hr/>
</form>

I have a few more selects in the form tag but here is where i have a problem. i need to just add the field and not refresh any of the the data the person has added.Thankinging you for your replies.

Upvotes: 2

Views: 1495

Answers (1)

Ram
Ram

Reputation: 144679

You can use clone:

$('#newField').click(function(){
    $('select[name=location]:first').clone().insertAfter('select:last')
})

Fiddle

Note that you should not use # in your id attributes.

<a href="#" id="#newField">Add location</a>
         //-----^

Upvotes: 4

Related Questions