Jump to content

change direction inside a text area


lofaifa

Recommended Posts

i have a textarea and two buttons .. my goal is when a user clicks a button the writing direction change (to rtl) , and when he clicks the other button he go back to normal direction ltr , the problem is i cant apply html tags inside a textarea cuz everything is considered a text !

 

 

any idea on how to do it ?

Link to comment
Share on other sites

if i did that , the whole text inside the text area will change direction .. and i dont want that (tried it)

 

what i want is if ur writing ltr (as default) normaly ,  and u want to write some code , it will be ugly to switch all of the provious text to rtl , soo what i want is that the previous text remains in the same direction and when u click the button ur actual direction change not the previous one , its like i wanna open a div inside the textarea with the direction u want and i put u inside it until u finished and u click back and u get out of the tag , soo that u still can see texts in different directions as u want inside ur textarea before u submit .

 

<textarea dir="rtl">
normal text
<div dir="ltr">
text with diferrent direction 
</div>
</textarea>

Link to comment
Share on other sites

i highly doubt that is possible with a normal textarea, as it is meant for plain, unformatted text.

 

what you want is almost like a wysiwyg editor. You could try an editable <div> instead of a textarea and append a inner <span> to reverse the text direction.

Link to comment
Share on other sites

i'm pretty sure contentEditable objects are not sent together with the other form elements when the form is submitted.

 

what you'll need to do is to use javascript to "copy" the contents of the contentEditable element, and add it into the form request e.g. by "pasting" into a hidden input element.

 

So the entire process is:

[*]User enters data into the div and clicks submit

[*]Javascript copies data from the div

[*]Pastes it into the a hidden input

[*]Continue with form submission

Link to comment
Share on other sites

there is a problem , i want to detect all html in my div tag

 

when i was working with textarea tag i used this :

 

var string=$(this).attr('value');

 

and its not working .. also this :

 

var string=$(this).text();

 

doesnt display html just text

 

and those :

 

string=document.getElementById('question_text').innerHTML;

string=$(this).html();

 

gives me back when the div is empty (or when i jump a line) :

 

<div><br></div> (empty text)

 

<div><br></div><div><br></div> (jumped a line whith nothing in first line)

 

<div> tags is appearing everywhere  :o

Link to comment
Share on other sites

i solved the other problem but im now in another html one .. when i insert the new span tag inside the original div tag it get the same direction and float of div (when im changing span attributes to rtl)

 

 

<div id="question_text" class="question" contenteditable="true">
<span id="spon">test</span>
</div>

 

#question_text{
direction:rtl; 
text-align:right; 
}

#question_text span{
direction:ltr; 
text-align:left; 
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.