Jump to content

Simple JAVA Script, Press / action


Fsoft

Recommended Posts

Hey,

 

I want to make a simple java script :)

 

What I want is to make a simple / small editor buttons.

 

So here we go.

 

 

There will be 4 HTML buttons and one text box.

 

And the buttons will be for Bold / Italic / Center / Underline.

 

So what I want is to have a javascript, but which if we select a particular text and click on B button, it will automatically get

[b]text here[/b]

 

I don't want users to manually do that :(

 

Please help. Thanks a lot :)

 

FAISAL!

Link to comment
https://forums.phpfreaks.com/topic/115020-simple-java-script-press-action/
Share on other sites


Place in header:

<script type="text/javascript"> 
<!-- 

function insertAtCursor(fieldID, myValue) { 

  fieldObj = document.getElementById(fieldID);

  if (document.selection)
  {
    //IE support 
    fieldObj.focus(); 
    sel = document.selection.createRange(); 
    sel.text = myValue; 
  } 
  else if (fieldObj.selectionStart || fieldObj.selectionStart == "0")
  {
    //Mozilla/Firefox/Netscape 7+ support 
    var startText = fieldObj.value.substring(0, fieldObj.selectionStart); 
    var endText = fieldObj.value.substring(fieldObj.selectionEnd, fieldObj.value.length); 
    fieldObj.value = startText + myValue + endText; 
  }
  else
  {
    //Unable to insert at current position - add to end of current value
    fieldObj.value += myValue; 
  }
} 

//--> 
</script> 

 

 

Sample link:


<a href="#" onClick="insertAtCursor('name_of_form','[b]text here[/b]'[b]text here[/b]</a>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.