Hi
I am having a problem with this code. Its near to working in firefox but not in IE. I want to be able to add a row and then if it is not appropriate remove it. I have spent ages trying to figure this out. Any help would be appreciated thank you. Once I have this sorted I then need to add hidden input fields so that the data is captured. Thanks again
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#bgColor {
background-color:silver;
}
</style>
<script type="text/javascript">
idCount=1;
function addFresh(elem) {
idCount++;
tRows = document.getElementById(elem);
tr = tRows.insertRow(tRows.rows.length);
if(idCount%2 != 0) tr.setAttribute("id","bgColor");
td = tr.insertCell(tr.cells.length);
td.innerHTML = document.getElementById("first").value;
td = tr.insertCell(tr.cells.length);
td.innerHTML = document.getElementById("second").value;
td = tr.insertCell(tr.cells.length);
td.innerHTML = document.getElementById("third").value;
td = tr.insertCell(tr.cells.length);
var removeButton = document.createElement("input");
removeButton.setAttribute("type","button");
removeButton.setAttribute("id", idCount);
removeButton.setAttribute("value","Remove");
removeButton.setAttribute("onclick","deleteFresh("+idCount+")");
td.appendChild(removeButton);
}
function deleteFresh(eleme) {
alert(eleme);
document.getElementById("mine").deleteRow(eleme);
eleme = "";
}
</script>
</head>
<body>
<form name="form1" action="untitled5.php" method="get">
<table id="mine" cellspacing="0" cellpadding="3" border="0">
<tr>
<td width="199">fruit</td>
<td width="185">veg</td>
<td width="147">quality</td>
<td width="153"></td>
</tr>
<tr>
<td>
<select id="first" name="first">
<option></option>
<option value="Apple">Apple</option>
<option value="Strawberry">Strawberry</option>
<option value="Banana">Banana</option>
<option value="Grape">Grape</option>
<option value="Orange">Orange</option>
</select>
</td>
<td>
<select id="second" name="second">
<option></option>
<option value="Cabage">Cabage</option>
<option value="Carrot">Carrot</option>
<option value="Onion">Onion</option>
</select>
</td>
<td>
<select id="third" name="third">
<option></option>
<option value="Fresh">Fresh</option>
<option value="Good">Good</option>
<option value="Very Good">Very Good</option>
</select>
</td><div id="fourth"></div>
<td><input type="button" name="add" value="add" onclick="addFresh('veg')"/></td>
</tr>
<tbody id="veg"></tbody>
</table>
</form>
</body>
</html>
I am having a problem with this code. Its near to working in firefox but not in IE. I want to be able to add a row and then if it is not appropriate remove it. I have spent ages trying to figure this out. Any help would be appreciated thank you. Once I have this sorted I then need to add hidden input fields so that the data is captured. Thanks again
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#bgColor {
background-color:silver;
}
</style>
<script type="text/javascript">
idCount=1;
function addFresh(elem) {
idCount++;
tRows = document.getElementById(elem);
tr = tRows.insertRow(tRows.rows.length);
if(idCount%2 != 0) tr.setAttribute("id","bgColor");
td = tr.insertCell(tr.cells.length);
td.innerHTML = document.getElementById("first").value;
td = tr.insertCell(tr.cells.length);
td.innerHTML = document.getElementById("second").value;
td = tr.insertCell(tr.cells.length);
td.innerHTML = document.getElementById("third").value;
td = tr.insertCell(tr.cells.length);
var removeButton = document.createElement("input");
removeButton.setAttribute("type","button");
removeButton.setAttribute("id", idCount);
removeButton.setAttribute("value","Remove");
removeButton.setAttribute("onclick","deleteFresh("+idCount+")");
td.appendChild(removeButton);
}
function deleteFresh(eleme) {
alert(eleme);
document.getElementById("mine").deleteRow(eleme);
eleme = "";
}
</script>
</head>
<body>
<form name="form1" action="untitled5.php" method="get">
<table id="mine" cellspacing="0" cellpadding="3" border="0">
<tr>
<td width="199">fruit</td>
<td width="185">veg</td>
<td width="147">quality</td>
<td width="153"></td>
</tr>
<tr>
<td>
<select id="first" name="first">
<option></option>
<option value="Apple">Apple</option>
<option value="Strawberry">Strawberry</option>
<option value="Banana">Banana</option>
<option value="Grape">Grape</option>
<option value="Orange">Orange</option>
</select>
</td>
<td>
<select id="second" name="second">
<option></option>
<option value="Cabage">Cabage</option>
<option value="Carrot">Carrot</option>
<option value="Onion">Onion</option>
</select>
</td>
<td>
<select id="third" name="third">
<option></option>
<option value="Fresh">Fresh</option>
<option value="Good">Good</option>
<option value="Very Good">Very Good</option>
</select>
</td><div id="fourth"></div>
<td><input type="button" name="add" value="add" onclick="addFresh('veg')"/></td>
</tr>
<tbody id="veg"></tbody>
</table>
</form>
</body>
</html>