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
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.

Link to comment
Share on other sites

  • 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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.