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
LVL 1
Westside2004Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kiran Paul VJComputer EngineerCommented:
use text area inside cell an show the data in the textarea, and set it as readonly, when the user clicked the edit button remove the readonly property, and edit as usual

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
0
SirCroftyCommented:
Is this what you had in mind?

<html>
<head>
<script language="JavaScript">

function changeTable()
{
      var tags = document.getElementsByTagName("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("INPUT");
                  newElem.id = 'input' + i;
                  newElem.value = val;
                  tags[i].appendChild(newElem);
            }
      }


}

</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>
0
Westside2004Author Commented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SirCroftyCommented:
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.
0
Kiran Paul VJComputer EngineerCommented:
try this, a modified version of SirCrofty's code,
not a good method but it works

<html>
<head>
<script language="JavaScript">

function changeTable()
{
     var tags = document.getElementsByTagName("pre");

     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("INPUT");
               newElem.id = 'input' + i;
               newElem.value = val;
               tags[i].appendChild(newElem);
          }
     }


}

</script>
</head>
<body>
     <table>
     <tr>
          <td>value 1</td>
     </tr>
     <tr>
          <td><pre>value 2</pre></td>
     </tr>
     </table>

     <input type="button" onclick="changeTable();" value="Edit">
</body>
</html>

hope this helps
kiranvj
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kiran Paul VJComputer EngineerCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.