Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 3
There are 1 users currently browsing forums.
PHP Scripting PHP is a scripting language for rapid web-development. It's a popular and powerful, OOP-capable language that is used by professionals. Discuss PHP here.

Reply
  #1  
Old 12-10-2009
cancer10's Avatar
A "Mature" Pre-Teenager!
 
Join Date: Jun 2005
Location: India
Age: 27
Posts: 515
Rep Power: 5
cancer10 is on a distinguished road
Question PHP / jQuery - Instant Editable Fields

Hi,

I was looking for a solution (using php/jquery) similar to the one as shown in the screen shot.

I have a user database with 3 fields:

id (auto number)
name (varchar)
email (varchar)

the user lists gets populated in a grid (html table), clicking on either the name or the email address would convert the label into an editable text box and after editing once i remove the cursor from the textbox, the data gets saved in the database.

Any help with a code snippet will be highly appreciated.

Thanks


Reply With Quote
  #2  
Old 12-10-2009
vento's Avatar
Sexy monkey
 
Join Date: May 2009
Location: Lithuania
Age: 16
Posts: 185
Rep Power: 1
vento is on a distinguished road
Re: PHP / jQuery - Instant Editable Fields

PHP is definitely not able to do this. You have to use JavaSript for this. It's a pretty simple one:
Code:
<html>
<body>
<div id="name"></div>
<form>
	<input type="text" id="nameField" onkeypress="updateName(this.value)"/>
</form>

<script type="text/javascript">
function updateName(sName)
{
	document.getElementById('name').innerHTML = sName;
}
</script>
</body>
</html>
I wrote it with all the HTML tags so you can copy-paste on your localhost and test it. But I believe that's exactly what you want. Isn't it?

There is another option to use onChange instead of onkeypress. This would give you an effect that the name field is updated when the focus is lost. Let's say that the user goes onto the next field.

---
I've got an idea that you might need this function for more than one input field. Here is what I would suggest:
Code:
<html>
<body>
<div id="name"></div>
<form>
	<input type="text" id="nameField" onkeypress="update(this.value, 'name')"/>
</form>

<script type="text/javascript">
function update(sName, element)
{
	if( typeof(element) == 'string' )
		element = document.getElementById(element);
	if( element == null )
		return;
	element.innerHTML = sName;
}
</script>
</body>
</html>
That checking can be removed if you won't forget to add quotes or send another element variable. I just prefer to check it before using. That causes less problems.
__________________

How to set up portable C++ IDE (Dev-C++)

Writing in C or C++ is like running a chain saw with all the safety guards removed," — Bob Gray.
Reply With Quote
  #3  
Old 12-11-2009
Moderator
 
Join Date: Dec 2005
Posts: 1,862
Rep Power: 6
Umang is on a distinguished road
Re: PHP / jQuery - Instant Editable Fields

You might also like to use AJAX to submit the newly made changes to a PHP page, which will record them in the database.
Reply With Quote


Reply


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

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collect 27 ebook learn php quyvphan PHP Articles 1 04-23-2009 05:52 PM
News: PHP 5.2.1 and PHP 4.4.5 Released PHP.net PHP Scripting 0 03-15-2007 01:31 PM