Current location: Hot Scripts Forums » Programming Languages » PHP » Converting from Output to Input !


Converting from Output to Input !

Reply
  #1 (permalink)  
Old 12-22-07, 11:11 AM
ausgezeichnete's Avatar
ausgezeichnete ausgezeichnete is offline
Wannabe Coder
 
Join Date: Oct 2007
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes Converting from Output to Input !

i want to edit a table but in the same page
when i click on Edit,the output value converts to input to be able to edit it
but i dont know why it didnt work????????
do u think it needs Ajax???
this is my code

PHP Code:

<table border="1" align="center">

  <tr>
    <th>Name</th>
  </tr>
  <?php do { ?>
    <tr>
    <?php if(!isset($_POST['Submit'])){?>
      <td><?php echo $row_Recordset1['porto_name']; ?></td>
      <?php }else{?>
      <td><input type=text value=<?php echo $row_Recordset1['porto_name']; ?> /></td>
      <?php }?>
      <td><input name="Submit" type="submit" value="edit"></td>
      
      
      <td><a href="portofolio_delete.php?porto_ID=<?php echo $row_Recordset1['porto_ID']; ?>">Delete</a></td>
      
    </tr>
    <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?>
</table>
Reply With Quote
  #2 (permalink)  
Old 12-28-07, 12:23 PM
Wolf1994 Wolf1994 is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Russia
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
First, you have no form to make submit work.
Second, strongly reccomend to use
Code:
$var="value";
<<<HTML
$var
text
HTML;
to make more readable code.
Third, you do not need form neither AJAX here at all. Just use something form JavaScript stuff like:
Code:
<div onclick='this.innerHTML="<input value=\"text\" />"'>text</div>
Did not checked code, so not sure that one really works.

Good luck!
Reply With Quote
  #3 (permalink)  
Old 12-30-07, 06:09 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Quote:
Originally Posted by Wolf1994 View Post
Third, you do not need form neither AJAX here at all.
Actually you do if you want to save the edited data, unless you want to submit the form (causing the page to refresh).

The javascript code Wolf1994 posted will work, but it will not display the actual content in the div, here's one that should do the trick:
Javascript Code:
  1. function setEditable (id) {
  2.   var object = document.getElementById(id);
  3.   var content = object.innerHTML;
  4.   object.innerHTML = '<textarea rows="10" cols="50">' + content + '</textarea>';
  5. }
In your html, you'll have to place this:
HTML Code:
<div id="the_div">content goes here</div>
<button type="button" name="edit" ondblclick="setEditable('the_div')">Edit</button>
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #4 (permalink)  
Old 12-30-07, 07:30 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Okay, I'm dense. How would you set that back to non-editable after editing?
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #5 (permalink)  
Old 12-30-07, 10:16 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Using the onblur event of the textarea, or either by adding a "save" button, like so:
Javascript Code:
  1. function setEditable (id) {
  2.   var object = document.getElementById(id);
  3.   var content = object.innerHTML;
  4.   object.innerHTML = '<textarea rows="10" cols="50" onblur="setNonEditable(' + id + ', this)">' + content + '</textarea>';
  5. }
  6.  
  7. function setNonEditable (div_id, textarea) {
  8.   var object = document.getElementById(div_id);
  9.   object.innerHTML = textarea.value;
  10. }
and the html:
HTML Code:
<div id="the_div">content goes here</div>
<button type="button" name="edit" onclick="setEditable('the_div')">Edit</button>
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #6 (permalink)  
Old 12-30-07, 12:24 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Cool. I'll learn something new every day if I'm not careful.

I had to give the text area an id and modify the save button a little bit to make it work right for me:

<button type="button" name="edit" onclick="setNonEditable('the_div', the_textarea)">Save</button>


Thanks Ed!
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #7 (permalink)  
Old 01-03-08, 02:50 AM
ausgezeichnete's Avatar
ausgezeichnete ausgezeichnete is offline
Wannabe Coder
 
Join Date: Oct 2007
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Well,frankly i didnt get it
this is my code
PHP Code:



<script type="text/javascript">
function setEditable (id) {
  var object = document.getElementById(id);
  var content = object.innerHTML;
  object.innerHTML = '<textarea rows="10" cols="50" onblur="setNonEditable(' + id + ', this)">' + content + '</textarea>';
}

function setNonEditable (div_id, textarea) {
  var object = document.getElementById(div_id);
  object.innerHTML = textarea.value;
}


</script>

<div id="the_div">
<?php 
$conn
=mysql_connect("localhost","root","123456");
$db=mysql_select_db("epic");
$Recordset1=mysql_query("select * from porto");
?>

<table border="1" align="center">
  <tr>
    <th>Name</th>
  <?php do { ?>
      <td><input type=text value=<?php echo $row_Recordset1['porto_name']; ?> /></td>
    </tr>
    <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?>
</table>
</div>
<button type="button" name="edit" onclick="setEditable('the_div')">Edit</button>
and i got in my page a table containing the data and a submit button called edit and i click on it the page changes to a text area containing that:
PHP Code:



<table align="center" border="1">
  <
tbody><tr>
    <
th>Name</th>
        <
td><input value="/" type="text"></td>
    </
tr>
          <
tr><td><input value="Web" design="" type="text"></td>
    </
tr>
          <
tr><td><input value="Web" develop="" type="text"></td>
    </
tr>
          <
tr><td><input value="maha" type="text"></td>
    </
tr>
          <
tr><td><input value="Web" type="text"></td>
    </
tr>
          <
tr><td><input value="Web" type="text"></td>
    </
tr>
          <
tr><td><input value="maha" type="text"></td>
    </
tr>
    </
tbody></table
i dont understand!!
Reply With Quote
  #8 (permalink)  
Old 01-03-08, 02:51 AM
ausgezeichnete's Avatar
ausgezeichnete ausgezeichnete is offline
Wannabe Coder
 
Join Date: Oct 2007
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
btw,my value in the table are
Web design
Web develop
maha
web
web
maha
Reply With Quote
  #9 (permalink)  
Old 05-05-08, 02:17 PM
BrianMedley BrianMedley is offline
Newbie Coder
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
I couldn't seem to get this working, I'll post what I had and hopefully somebody will see a mistake made.

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script src="../javascript/table_update.js" type="text/javascript"></script>
<title>Test</title>
</head>

<body>

<div id="the_div">Editable text!</div>
<button type="button" name="edit" onclick="setEditable('the_div')">Edit</button>

<button type="button" name="edit" onclick="setNonEditable('the_div', save)">Save</button>

</body>
</html>
here is the javascript file

Javascript Code:
  1. function setEditable (id) {
  2.     var object = document.getElementById(id);
  3.     var content = object.innerHTML;
  4.     object.innerHTML = '<textarea id="save" rows="10" cols="50" onblur="setNonEditable(' + id + ', this)">' + content + '</textarea>';
  5. }
  6.  
  7. function setNonEditable (div_id, textarea) {
  8.     var object = document.getElementById(div_id);
  9.     object.innerHTML = textarea.value;
  10. }

Last edited by UnrealEd; 05-06-08 at 02:53 AM. Reason: proper syntax highlighting
Reply With Quote
  #10 (permalink)  
Old 05-06-08, 02:58 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
This time I tested the code, and it all works fine in FireFox:
Javascript Code:
  1. function setEditable (id) {
  2.     var object = document.getElementById(id);
  3.     var content = object.innerHTML;
  4.     object.innerHTML = '<textarea id="save" rows="10" cols="50" onblur="setNonEditable(\'' + id + '\', \'save\')">' + content + '</textarea>';
  5. }
  6.  
  7. function setNonEditable (div_id, textarea) {
  8.     try {
  9.         var object = document.getElementById(div_id);
  10.         object.innerHTML = document.getElementById(textarea).value;
  11.     } catch (e) {}
  12. }
And the HTML:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script src="../javascript/table_update.js" type="text/javascript"></script>
<title>Test</title>
</head>

<body>

<div id="the_div">Editable text!</div>
<button type="button" name="edit" onclick="setEditable('the_div')">Edit</button>

<button type="button" name="edit" onclick="setNonEditable('the_div', 'save')">Save</button>

</body>
</html>
Enjoy!
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CSV problem Nikas PHP 224 08-03-07 01:26 AM
Assembler Coding downsouth The Lounge 1 12-18-06 02:58 AM
Getting wrong output INTEL C/C++ 3 10-09-06 04:22 PM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 07:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.