3

I'm adding <input> fields in form using jquery html() on click event.

$('#container').html('<input type="text" name="ce" value="some" >');

after submitting php POST i'm unable to see index ce with print_r($_POST);

is there any special method to add elements to dom for this ? please advise.

2
  • 1
    How about using .append() instead of .html()? Commented Sep 20, 2015 at 9:49
  • Show us the rest of your form html and make sure the new input field is inside the form element. Commented Sep 20, 2015 at 9:51

2 Answers 2

3

Solved ! Thanks for answering. in my scenario even with append it didn't work. now it's done with my previous code using html(). Problem was wrapping the <form>. my table is large i'm only pointing out the problem. my structure was suppose to like:

<table>
<tr>
<form id="myform">
<td><input type="text" name="name" ></td>
<td>
<div id="container">
<!-- dynamically generated inside this div against it's id (which didn't work) -->
<input type="text" name="ce" >  
</div>
</td>
</form>
</tr>
</table>

i simply Put the entire table into the 'form' tags

<form id="myform">
<table>
<tr>
<td><input type="text" name="name" ></td>
<td>
<div id="container">
<input type="text" name="ce" > <!-- dynamically generated inside div (works!) -->
</div>
</td>
</tr>
</table>
</form>

it worked perfectly with both append() and html(). hope will be helpful for someone.

Sign up to request clarification or add additional context in comments.

Comments

1

When you do $('#container').html you are not adding a new input, you are replacing all your content with this new input..

try $('#container').append tag

Look at this example -> https://jsfiddle.net/660a3t1g/

    $('#myInputs').append('<input type="text" placeholder="LastName: " name="some" >');  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.