Westside2004
asked on
Changing a cell into a text box???
Hi,
I have a query that generates an HTML table of products, and there is an "edit" icon that when clicked basically takes the user to another page where there is a form, in the form I display the data from the table of products with a "Save" Button, so the user can edit the product data like, name, desc, etc, etc hit save, and they are redirected back to the product list.
I am trying to find a way to have the individual cells in my html table become editable. Basically like an editable grid, you click the edit icon and then the data in th cells would change to an html text input box. This way the user can essentially stay on the same page as opposed to going on to another page. Is there a way to do this with CSS and or JavaScript?
Any help appreciated.
Thanks
Malik
I have a query that generates an HTML table of products, and there is an "edit" icon that when clicked basically takes the user to another page where there is a form, in the form I display the data from the table of products with a "Save" Button, so the user can edit the product data like, name, desc, etc, etc hit save, and they are redirected back to the product list.
I am trying to find a way to have the individual cells in my html table become editable. Basically like an editable grid, you click the edit icon and then the data in th cells would change to an html text input box. This way the user can essentially stay on the same page as opposed to going on to another page. Is there a way to do this with CSS and or JavaScript?
Any help appreciated.
Thanks
Malik
Is this what you had in mind?
<html>
<head>
<script language="JavaScript">
function changeTable()
{
var tags = document.getElementsByTagN ame("TD");
for (i = 0; i < tags.length; i++)
{
var val = tags[i].innerHTML;
if (val.indexOf('<') < 0)
{
tags[i].innerHTML = '';
var ar = new Array();
var newElem = document.createElement("IN PUT");
newElem.id = 'input' + i;
newElem.value = val;
tags[i].appendChild(newEle m);
}
}
}
</script>
</head>
<body>
<table>
<tr>
<td>value 1</td>
</tr>
<tr>
<td>value 2</td>
</tr>
</table>
<input type="button" onclick="changeTable();" value="Edit">
</body>
</html>
<html>
<head>
<script language="JavaScript">
function changeTable()
{
var tags = document.getElementsByTagN
for (i = 0; i < tags.length; i++)
{
var val = tags[i].innerHTML;
if (val.indexOf('<') < 0)
{
tags[i].innerHTML = '';
var ar = new Array();
var newElem = document.createElement("IN
newElem.id = 'input' + i;
newElem.value = val;
tags[i].appendChild(newEle
}
}
}
</script>
</head>
<body>
<table>
<tr>
<td>value 1</td>
</tr>
<tr>
<td>value 2</td>
</tr>
</table>
<input type="button" onclick="changeTable();" value="Edit">
</body>
</html>
ASKER
Hi,
This does work SirCrofty, but it changes all td's. I have an HTML table that has some data I dont want to turn into input fields.
How can I control individual "<td's> essentially. I have rows of data. Each row is editable by clicking the edit icon next to that row. The above code makes all td's into input boxes.
Thanks,
-ws
This does work SirCrofty, but it changes all td's. I have an HTML table that has some data I dont want to turn into input fields.
How can I control individual "<td's> essentially. I have rows of data. Each row is editable by clicking the edit icon next to that row. The above code makes all td's into input boxes.
Thanks,
-ws
You could just give each td you want to change an id/attribute and check for that attribute in the loop I suppose, and then change only those tds that have that identifier.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and if u want to change the font of text inside the pre tags u can use this
<style type="text/css">
<!--
pre {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
text-decoration: none;
}
-->
</style>
paste it in the head tag.
but here also there is the problem, all pre tags will be converted to text fields,
but pre tags are rarely used in a web page.
kiranvj
<style type="text/css">
<!--
pre {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
text-decoration: none;
}
-->
</style>
paste it in the head tag.
but here also there is the problem, all pre tags will be converted to text fields,
but pre tags are rarely used in a web page.
kiranvj
code to show textarea with no borders
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.txtB {
height: 150px;
width: 200px;
border: none;
overflow:auto;
}
-->
</style>
</head>
<body>
<form name="form1" method="post" action="">
<textarea name="textarea" class="txtB"></textarea>
</form>
</body>
</html>
kiranvj