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
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>

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.