Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to schange marked text in a textfield vith a form button

Status
Not open for further replies.

brynjan

Programmer
May 7, 2001
5
0
0
SE
I have made a textfield that submit html to a db site and now i want to make it possible to change the text that is typed with a form button.

Ex. text written in the textfield:
Hi my name is johan

after this you should beenabel to mark johan with the mouse and press a form button and then the textfiled should be like this:

Hi my name is <b>johan</b>

Does anyone have a soulotion to this problem?
 
hie
try this:
~script:
function boldit(){
sel=document.selection
range=sel.createRange()
thetext=range.text
if (thetext.length){
range.text=&quot;<b>&quot;+thetext+&quot;</b>&quot;
}
}
..

~form:
..
<input type=button value=&quot;bold me&quot; onclick=&quot;boldit()&quot;>
..

but be warned: this would change EVERYTHING on the page that would be selected on the moment of button clicking (i mean if you'll select something outside your textfield/area, then it would be changed to &quot;<b>&quot;+..+&quot;</b>&quot; as well)
 
thx tuz

have written this but it wont work, what have i done wrong

<SCRIPT LANGUAGE=&quot;JavaScrippt&quot;>

function boldit()
{
sel=document.selection
range=sel.createRange()
thetext=range.text
if (thetext.length)
{
range.text=&quot;<b>&quot;+thetext+&quot;</b>&quot;
}
}

</script>


<form>


<input type=&quot;text&quot; name=&quot;textfield&quot;>
<input type=button value=&quot;bold me&quot; onclick=&quot;boldit()&quot;>

</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top