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 04-27-2011, 08:55 AM   PM User | #1
walkie
New Coder

 
Join Date: Jul 2010
Posts: 30
Thanks: 3
Thanked 0 Times in 0 Posts
walkie is an unknown quantity at this point
Change text-input to textarea

Dear Coders,

I'm having a little problem converting the below code from <input type="text"> to <textarea></textarea> because it's inside a java code, that I don't quite understand.

Code:
$('<input type="text">').val(container.text()).appendTo(container.empty());
I guess this ".find" function needs to be changed as well:

Code:
$('.todo a.saveChanges').live('click',function(){
		var text = currentTODO.find("input[type=text]").val();
...

Please let me know if you need to see more of the script in order to help

Thanks in advance.

Morten
walkie is offline   Reply With Quote
Old 04-27-2011, 09:00 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Try to do that:
Code:
$('<textarea>').val(container.text()).appendTo(container.empty());
and
Code:
$('.todo a.saveChanges').live('click',function(){
		var text = currentTODO.find("textarea").val();
...
devnull69 is offline   Reply With Quote
Old 04-27-2011, 09:02 AM   PM User | #3
walkie
New Coder

 
Join Date: Jul 2010
Posts: 30
Thanks: 3
Thanked 0 Times in 0 Posts
walkie is an unknown quantity at this point
Thank you for the answer.
Where/how do i end the textarea tag?
walkie is offline   Reply With Quote
Old 04-27-2011, 09:10 AM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
It kind of ends itself :-)

This code
Code:
$('<textarea>').appendTo(...);
will create a complete <textarea> and append it to the destination. This complete tag will include the closing tag.
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
walkie (04-27-2011)
Old 04-27-2011, 09:17 AM   PM User | #5
walkie
New Coder

 
Join Date: Jul 2010
Posts: 30
Thanks: 3
Thanked 0 Times in 0 Posts
walkie is an unknown quantity at this point
Aaah cool!
Because I tried myself with this:

Code:
$('<textarea>').val(container.text()).appendTo(container.empty()).('</textarea>');
And i kinda knew it was wrong, but worth the try hehe.

I can add a parameter to the textarea inthere right? Like this:

Code:
$('<textarea class="name">').val(container.text()).appendTo(container.empty());
walkie is offline   Reply With Quote
Old 04-27-2011, 09:18 AM   PM User | #6
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Yes, you can
devnull69 is offline   Reply With Quote
Old 04-27-2011, 09:26 AM   PM User | #7
walkie
New Coder

 
Join Date: Jul 2010
Posts: 30
Thanks: 3
Thanked 0 Times in 0 Posts
walkie is an unknown quantity at this point
Thanks alot for you help mate.

Would you mind if I PM you if I have some other small problems with jQuery? You seem to know your way around it, and i wont abuse it.
Or would you prefer if I make new posts?
walkie is offline   Reply With Quote
Old 04-27-2011, 12:17 PM   PM User | #8
walkie
New Coder

 
Join Date: Jul 2010
Posts: 30
Thanks: 3
Thanked 0 Times in 0 Posts
walkie is an unknown quantity at this point
So the textarea is now showing, but there's a problem with saving the text now.
When i press save, the new text shows, but it does not update the MySQL. Because when I press refresh, it disappears.

Here's what i have.

The save function:
Code:
	$('.todo a.saveChanges').live('click',function(){
		var text = currentTODO.find("textarea").val();
		
		$.get("ajax.php",{'action':'edit','id':currentTODO.data('id'),'text':text});
		
		currentTODO.removeData('origText')
					.find(".text")
					.text(text);
	});

Which leads to the "edit case" in ajax.php:
Code:
case 'edit':
	ToDo::edit($id,$_GET['text']);
	break;

That calls the function for updating the database:
Code:
public static function edit($id, $text){

	$text = self::esc($text);
	if(!$text) throw new Exception("Wrong update text!");

	mysql_query("	UPDATE tabel
					SET text='".$text."'
					WHERE id=".$id
				);
		
	if(mysql_affected_rows($GLOBALS['link'])!=1)
		throw new Exception("Couldn't update item!");
}

This worked before we changed to the textarea
Can you see why?


/Morten
walkie is offline   Reply With Quote
Old 04-27-2011, 12:30 PM   PM User | #9
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
I'm not sure exactly what you are trying to do

Are you trying to swap a text box element for a textarea and what event (button click?) triggers the swap. And what if there is something entered in the text box when the swap is triggered.

The reason I ask is because it might be just a few lines of plain javascript if the above is all you want to do.
bullant is offline   Reply With Quote
Old 04-27-2011, 12:58 PM   PM User | #10
walkie
New Coder

 
Join Date: Jul 2010
Posts: 30
Thanks: 3
Thanked 0 Times in 0 Posts
walkie is an unknown quantity at this point
Hey Bullant,

Thank you for your answer.

It is a free script I have downloaded and trying to change to match my needs. Therefore I Didn't want it to be a <input type=text> but instead a <textarea>.

devnull69 helped me change that, but now the script wont save what i type in the field.
You can press a button called "edit" and it turns into a writeable textfield, and then press save and it should upload the changes to a Database.
It shows the changes like it should, but does not upload to the database anymore.


I hope this helped you understand what the script does.

Br,
Morten
walkie is offline   Reply With Quote
Old 04-27-2011, 09:00 PM   PM User | #11
walkie
New Coder

 
Join Date: Jul 2010
Posts: 30
Thanks: 3
Thanked 0 Times in 0 Posts
walkie is an unknown quantity at this point
I found the error in the tabel name So know it works!

Thanks alot for all your help.
walkie is offline   Reply With Quote
Reply

Bookmarks

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 04:58 AM.


Advertisement
Log in to turn off these ads.