Jump to content

adding form elements dynamically


void

Recommended Posts

hi guys,

 

I've come across an issue. looks like if I add an input field in a simple way, that is, appending html code of a field to innerHTML on a div, it doesn't actually create an element. it appears visually, but if i submit the form, there is no sign of that field. any ideas why could that be?

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/175532-adding-form-elements-dynamically/
Share on other sites

What exactly do you mean with "it appears visually"? Does it show a new input field when you're appending html code of a field to innerHTML.

 

Could you post the code that you're using to create the a new field?

 

Another note, once you submit your form the text fields you create using javascript won't be rebuild on the form unless you've handle this serverside somehow.

  • 2 months later...

Okay, I'm back to this problem. Thanks for your replies.

 

Here's the thing. I have something like:

 

<form action="" method="post">
<div id="extra">

</div>
<input type="text" name="something" value="test" />
<input type="submit" name="submit" value="Submit!" />
</form>

 

So let's say I call this javascript function from somewhere:

 

document.getElementById('extra').innerHTML = '<input type="text" name="field1" value="" />';

 

The text field appers on a page, but if I enter some text and submit the form, it doesn't post the info from that field. For example, if I do print_r($_POST); I see [field1] => [something] => test.

 

Any idea what's the problem?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.