/    Sign up×
Community /Pin to ProfileBookmark

need Javascript help to build add and delete a row

Hi,
I do not know how to create function delete row with javascript.
perhaps someone can help me.
here is the javascript code

[code=php]<script>
function add_formrow(){
if (!this.table_formcontainer)
this.table_formcontainer = document.getElementById(“table_formcontainer”);

if (!this.table_formcontainer)
return;

var new_row = table_formcontainer.insertRow(-1);
var new_cell1 = new_row.insertCell(0);
var new_cell2 = new_row.insertCell(1);
var new_cell3 = new_row.insertCell(2);

var new_input1 = document.createElement(“input”);
new_input1.type = “text”;
new_cell1.appendChild(new_input1);

var new_input2 = document.createElement(“input”);
new_input2.type = “text”;
new_cell2.appendChild(new_input2);

var new_input3 = document.createElement(“select”);
new_input3.name=”transport[]”;
var options = [“Bike”, “Car”, “Motorbike”, “Public transport”] ;
for (var i = 0; i < options.length; i++)
{
var option = document.createElement(“option”);
option.value = options[i];
option.text= options[i];
try
{
new_input3.add(option, null);
}
catch(error)
{
new_input3.add(option);
}
}
new_cell3.appendChild(new_input3);
}

[/code]

thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorDec 24.2008 — [code=php]
function del_formrow(n)
{
if (!this.table_formcontainer)
this.table_formcontainer = document.getElementById("table_formcontainer");

if (!this.table_formcontainer)
return;

table_formcontainer.deleteRow(n);
}
[/code]


Parameter is the row number you want to delete (zero indexing).
Copy linkTweet thisAlerts:
@redskinauthorDec 24.2008 — great its work,

thanks a lot.
×

Success!

Help @redskin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...