How remove dynamic fields with Javascript
I am learning javascript with dynamic fields and I wanted to be able to eliminate them besides making them match with the table,to later use css
I just need to use javascript
javascript code:
function create()
var div = document.getElementById("fields");
var array=document.getElementsByName('txt');
var length = array.length+1;
var jump = document.createElement("P");
var input = document.createElement("input");
input.setAttribute("name", "txt");
input.setAttribute("id", "txtCamp" + length);
input.setAttribute("size", "20");
input.className = "input";
var input2 = document.createElement("input");
input2.setAttribute("name", "txt2");
input2.setAttribute("id", "txtCamp2" + length);
input2.setAttribute("size", "20");
input2.className = "input";
var button = document.createElement('button');
button.setAttribute("type", "button");
button.setAttribute("id", "txtCampo3"+ length);
button.innerHTML = 'Add field';
button.setAttribute("onclick", "create()");
var button2 = document.createElement('button');
button2.setAttribute("type", "button");
button2.setAttribute("id", "txtCampo3"+ length);
button2.innerHTML = 'delete field';
jump.appendChild(input);
jump.appendChild(input2);
jump.appendChild(button);
jump.appendChild(button2);
div.appendChild(jump);
And the table in html
<table width="50%" border="0" cellspacing="5" cellpadding="7">
<tr>
<td>
<input type="button" id="boton" value="Create field" onclick="create();" />
</td>
</tr>
<tr>
<th>Item1</th>
<th>Item2</th>
</tr>
<tr> <td>
<div id="fields"></div>
</td>
</tr>
</table>
javascript html field
add a comment |
I am learning javascript with dynamic fields and I wanted to be able to eliminate them besides making them match with the table,to later use css
I just need to use javascript
javascript code:
function create()
var div = document.getElementById("fields");
var array=document.getElementsByName('txt');
var length = array.length+1;
var jump = document.createElement("P");
var input = document.createElement("input");
input.setAttribute("name", "txt");
input.setAttribute("id", "txtCamp" + length);
input.setAttribute("size", "20");
input.className = "input";
var input2 = document.createElement("input");
input2.setAttribute("name", "txt2");
input2.setAttribute("id", "txtCamp2" + length);
input2.setAttribute("size", "20");
input2.className = "input";
var button = document.createElement('button');
button.setAttribute("type", "button");
button.setAttribute("id", "txtCampo3"+ length);
button.innerHTML = 'Add field';
button.setAttribute("onclick", "create()");
var button2 = document.createElement('button');
button2.setAttribute("type", "button");
button2.setAttribute("id", "txtCampo3"+ length);
button2.innerHTML = 'delete field';
jump.appendChild(input);
jump.appendChild(input2);
jump.appendChild(button);
jump.appendChild(button2);
div.appendChild(jump);
And the table in html
<table width="50%" border="0" cellspacing="5" cellpadding="7">
<tr>
<td>
<input type="button" id="boton" value="Create field" onclick="create();" />
</td>
</tr>
<tr>
<th>Item1</th>
<th>Item2</th>
</tr>
<tr> <td>
<div id="fields"></div>
</td>
</tr>
</table>
javascript html field
1
You mean you want to remove attributes from the created nodes? Or that you want to remove elements altogether?
– Federico klez Culloca
Nov 12 at 11:25
yes sir i need to remove from the created nodes
– Sandor
Nov 12 at 11:35
ThenremoveAttributeis probably what you need.
– Federico klez Culloca
Nov 12 at 11:36
Thank you very much!!! and how it would be remove elements altogether?
– Sandor
Nov 12 at 11:40
For that you needremove
– Federico klez Culloca
Nov 12 at 11:42
add a comment |
I am learning javascript with dynamic fields and I wanted to be able to eliminate them besides making them match with the table,to later use css
I just need to use javascript
javascript code:
function create()
var div = document.getElementById("fields");
var array=document.getElementsByName('txt');
var length = array.length+1;
var jump = document.createElement("P");
var input = document.createElement("input");
input.setAttribute("name", "txt");
input.setAttribute("id", "txtCamp" + length);
input.setAttribute("size", "20");
input.className = "input";
var input2 = document.createElement("input");
input2.setAttribute("name", "txt2");
input2.setAttribute("id", "txtCamp2" + length);
input2.setAttribute("size", "20");
input2.className = "input";
var button = document.createElement('button');
button.setAttribute("type", "button");
button.setAttribute("id", "txtCampo3"+ length);
button.innerHTML = 'Add field';
button.setAttribute("onclick", "create()");
var button2 = document.createElement('button');
button2.setAttribute("type", "button");
button2.setAttribute("id", "txtCampo3"+ length);
button2.innerHTML = 'delete field';
jump.appendChild(input);
jump.appendChild(input2);
jump.appendChild(button);
jump.appendChild(button2);
div.appendChild(jump);
And the table in html
<table width="50%" border="0" cellspacing="5" cellpadding="7">
<tr>
<td>
<input type="button" id="boton" value="Create field" onclick="create();" />
</td>
</tr>
<tr>
<th>Item1</th>
<th>Item2</th>
</tr>
<tr> <td>
<div id="fields"></div>
</td>
</tr>
</table>
javascript html field
I am learning javascript with dynamic fields and I wanted to be able to eliminate them besides making them match with the table,to later use css
I just need to use javascript
javascript code:
function create()
var div = document.getElementById("fields");
var array=document.getElementsByName('txt');
var length = array.length+1;
var jump = document.createElement("P");
var input = document.createElement("input");
input.setAttribute("name", "txt");
input.setAttribute("id", "txtCamp" + length);
input.setAttribute("size", "20");
input.className = "input";
var input2 = document.createElement("input");
input2.setAttribute("name", "txt2");
input2.setAttribute("id", "txtCamp2" + length);
input2.setAttribute("size", "20");
input2.className = "input";
var button = document.createElement('button');
button.setAttribute("type", "button");
button.setAttribute("id", "txtCampo3"+ length);
button.innerHTML = 'Add field';
button.setAttribute("onclick", "create()");
var button2 = document.createElement('button');
button2.setAttribute("type", "button");
button2.setAttribute("id", "txtCampo3"+ length);
button2.innerHTML = 'delete field';
jump.appendChild(input);
jump.appendChild(input2);
jump.appendChild(button);
jump.appendChild(button2);
div.appendChild(jump);
And the table in html
<table width="50%" border="0" cellspacing="5" cellpadding="7">
<tr>
<td>
<input type="button" id="boton" value="Create field" onclick="create();" />
</td>
</tr>
<tr>
<th>Item1</th>
<th>Item2</th>
</tr>
<tr> <td>
<div id="fields"></div>
</td>
</tr>
</table>
javascript html field
javascript html field
edited Nov 12 at 11:26
Federico klez Culloca
15.6k134275
15.6k134275
asked Nov 12 at 11:20
Sandor
123
123
1
You mean you want to remove attributes from the created nodes? Or that you want to remove elements altogether?
– Federico klez Culloca
Nov 12 at 11:25
yes sir i need to remove from the created nodes
– Sandor
Nov 12 at 11:35
ThenremoveAttributeis probably what you need.
– Federico klez Culloca
Nov 12 at 11:36
Thank you very much!!! and how it would be remove elements altogether?
– Sandor
Nov 12 at 11:40
For that you needremove
– Federico klez Culloca
Nov 12 at 11:42
add a comment |
1
You mean you want to remove attributes from the created nodes? Or that you want to remove elements altogether?
– Federico klez Culloca
Nov 12 at 11:25
yes sir i need to remove from the created nodes
– Sandor
Nov 12 at 11:35
ThenremoveAttributeis probably what you need.
– Federico klez Culloca
Nov 12 at 11:36
Thank you very much!!! and how it would be remove elements altogether?
– Sandor
Nov 12 at 11:40
For that you needremove
– Federico klez Culloca
Nov 12 at 11:42
1
1
You mean you want to remove attributes from the created nodes? Or that you want to remove elements altogether?
– Federico klez Culloca
Nov 12 at 11:25
You mean you want to remove attributes from the created nodes? Or that you want to remove elements altogether?
– Federico klez Culloca
Nov 12 at 11:25
yes sir i need to remove from the created nodes
– Sandor
Nov 12 at 11:35
yes sir i need to remove from the created nodes
– Sandor
Nov 12 at 11:35
Then
removeAttribute is probably what you need.– Federico klez Culloca
Nov 12 at 11:36
Then
removeAttribute is probably what you need.– Federico klez Culloca
Nov 12 at 11:36
Thank you very much!!! and how it would be remove elements altogether?
– Sandor
Nov 12 at 11:40
Thank you very much!!! and how it would be remove elements altogether?
– Sandor
Nov 12 at 11:40
For that you need
remove– Federico klez Culloca
Nov 12 at 11:42
For that you need
remove– Federico klez Culloca
Nov 12 at 11:42
add a comment |
1 Answer
1
active
oldest
votes
you can write a function by first getting that particular element and then you can remove it for example
function removeElt(elementId)
var element = document.getElementById(elementId);
element.parentNode.removeChild(element);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261096%2fhow-remove-dynamic-fields-with-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can write a function by first getting that particular element and then you can remove it for example
function removeElt(elementId)
var element = document.getElementById(elementId);
element.parentNode.removeChild(element);
add a comment |
you can write a function by first getting that particular element and then you can remove it for example
function removeElt(elementId)
var element = document.getElementById(elementId);
element.parentNode.removeChild(element);
add a comment |
you can write a function by first getting that particular element and then you can remove it for example
function removeElt(elementId)
var element = document.getElementById(elementId);
element.parentNode.removeChild(element);
you can write a function by first getting that particular element and then you can remove it for example
function removeElt(elementId)
var element = document.getElementById(elementId);
element.parentNode.removeChild(element);
answered Nov 12 at 11:45
Haris
679
679
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261096%2fhow-remove-dynamic-fields-with-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You mean you want to remove attributes from the created nodes? Or that you want to remove elements altogether?
– Federico klez Culloca
Nov 12 at 11:25
yes sir i need to remove from the created nodes
– Sandor
Nov 12 at 11:35
Then
removeAttributeis probably what you need.– Federico klez Culloca
Nov 12 at 11:36
Thank you very much!!! and how it would be remove elements altogether?
– Sandor
Nov 12 at 11:40
For that you need
remove– Federico klez Culloca
Nov 12 at 11:42