Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-01-2012, 05:52 PM   PM User | #1
jcdevelopment
Senior Coder

 
jcdevelopment's Avatar
 
Join Date: Oct 2007
Location: Cowboy Nation
Posts: 2,171
Thanks: 173
Thanked 257 Times in 257 Posts
jcdevelopment will become famous soon enoughjcdevelopment will become famous soon enough
JQuery editable input fields

I have a script for taking static text then being able to edit it on the fly by making it an input field. Works great except how can I make it for multiple fields?

Each time I change the text all of them change, which I understand because all are named the same class. Any help or suggestions are very helpful. Thanks.

Code:
$(document).ready(function() {	
	$("div.edit").click(function() {		
		if ($(this).children('input').length == 0) {		
		var inputbox = "<input type='text' class='inputbox' value=\""+$(this).text()+"\">";
			$(this).html(inputbox);
			$("input.inputbox").focus();
			$("input.inputbox").blur(function() {
				var value = $(this).val();
				$(".edit").text(value);
			});
		}
	});
});
Code:
<tr>
					<td><div class="edit">Home</div></td>
					<td> <a href=""><img src="_gfx/cross.png" /></a></td>
				
				</tr>
				
				<tr class="odd">
					<td><div class="edit">Products</div></td>
					<td> <a href=""><img src="_gfx/cross.png" /></a></td>
				
				</tr>
jcdevelopment is offline   Reply With Quote
Old 06-01-2012, 07:00 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
Code:
$(document).ready(function() {    
    $("div.edit").click(function() {        
        if ($(this).children('input').length == 0) {        
        var inputbox = "<input type='text' class='inputbox' value=\""+$(this).text()+"\">";
            $(this).html(inputbox);
            $(".inputbox").focus();
            $(".inputbox").blur(function() {
                var value = $(this).val();
                $(this).parent().text(value);
            });
        }
    });
});​

Last edited by xelawho; 06-01-2012 at 07:37 PM..
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
jcdevelopment (06-01-2012)
Reply

Bookmarks

Tags
input, jquery, text

Jump To Top of Thread


Thread Tools
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

Forum Jump


All times are GMT +1. The time now is 07:06 PM.


Advertisement
Log in to turn off these ads.