![]() |
How to remove appendchild?
Hi,
I have created a form whereby user will see 1 row with 2 fields and a add button initially. When user click on the add button, another row will appear etc. However, I am stuck on how to remove those appendchild? Can someone please kindly help? Thanks Example: User click add button, 1 row appear with a remove link behind that row. If user click another time add button, 1 more row appear with another remove link etc. So if user click on the remove link that belong to that row, the appendchild will be remove. ------------------------------------------------------------------ <script type="text/javascript"> function addInput(){ var tbl = document.getElementById('tblAddress'); var lastRow = tbl.rows.length; var row = tbl.insertRow(lastRow); var cell0 = row.insertCell(0); var el = document.createElement('input'); el.type='text'; el.name='name[]'; cell0.appendChild(el); var cell1 = row.insertCell(1); var el = document.createElement('input'); el.type ='text'; el.name='address[]'; cell1.appendChild(el); } </script> <table align="center" border="1" id="tblAddress"> <tr> <td><b>Name</b></td> <td><b>Address</b></td> </tr> <tr> <td><input type="text" name="name[]"></td> <td><input type="text" name="address[]"></td> </tr> </table> <p align="center"><input type="button" value="Add" onClick="addInput();"></p> |
Try this:-
Code:
<html> |
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
Quote:
I am trying to add an alert prompt if any of the fields are empty. For the first row, i can successfully prompt user. However, if i click on add, those appendchild will not be prompt alert if it is null. Can kindly advice on this? Thanks. <script type="text/javascript"> function validateForm(){ var x=document.forms["form"]["name[]"].value; var y=document.forms["form"]["address[]"].value; if (x=="" || x==null){ alert("Please fill in name field!"); return false; }else if (y=="" || y==null){ alert("Please fill in address field!"); return false; } } </script> |
| All times are GMT +1. The time now is 07:17 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.