Page 1 of 1

Add contect to textfield using buttons

Posted: Tue May 05, 2009 7:51 am
by deejay
Hi

At present I have created a simple webpage that has a form so I can update a blog from my mobile.

I would like to couple of buttons that would add content to the textarea , a bit like http://tinymce.moxiecode.com/ but as this page would be accessed on mobiles I'd like to keep it real simple.

so far I have

Code: Select all

 
<script type="text/javascript" language="javascript">
 
function MkeBold()
{
   var MyElement = document.getElementById("introtext");
   MyElement.value = "<b></b>";
 
   return true;
}
 
function AddImg()
{
   var MyElement = document.getElementById("introtext");
   MyElement.value = "<img src=\"http://www.wavelengthmag.co.uk/images/A ... GENAMEHERE\">";
 
   return true;
}
 
</script>
 

Code: Select all

 
<img src="images/buttons/bold.gif" alt="BOLD" onClick="MkeBold()" /> 
                                    <TEXTAREA WRAP=PHYSICAL NAME="introtext" ROWS=4 COLS=25 id="introtext"></TEXTAREA>
the problem with this is that it'll write over everything that's in the box. Can anyone push me in the right direction for a better solution.

Thanks in advance

Re: Add contect to textfield using buttons

Posted: Tue May 05, 2009 10:25 am
by pickle
There is a way (not sure exactly how) to determine where the cursor position is in a textfield, then insert text at that position.

Re: Add contect to textfield using buttons

Posted: Tue May 05, 2009 11:12 am
by kaszu
It's almost the same as what editor on phpBB forums does except instead of BB code you have html, check 'insert_text' function in styles/prosilver/template/editor.js

Re: Add contect to textfield using buttons

Posted: Wed May 06, 2009 5:12 am
by deejay
Cheers guys

I had a quick search for 'cursor position is in a textfield' last night, but it seems pretty browser specific; which puts me off when we'll be looking to access this page from mobile devices.

kaszu :

I don't suppose you've got an example of the call up for this funtion. that way I could look at using it without having to understand how it works. Am hoping to get a spare moment at sometime to have a closer look at it.

Think I'm going to shelf this for a moment and maybe think of an easier solution.