SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    <b></b> are created at the end of the message

    Code:
    <script type="text/javascript">
       function appendValue(str)
      {
      document.forms[0]['t'].value += str;
      }	
    </script>
    
    <form action="form_action.php">	
    <input type="button" value=" b " onclick="appendValue('<b>');">
    <input type="button" value=" /b " onclick="appendValue('</b>');">
    <textarea name="message" id="t" cols="76" rows="20"></textarea>
    <input type="submit" value="Submit">
    </form>
    The above javascript makes users can add <b> or </b> by one click while they enter their message.

    It generally works fine, but has one problem.

    The problem is <b> or </b> is added at the end of message.

    For example,

    A user is trying to enter his message " My name is <b>John</b>".
    If his behavior is like the following, it's okay.

    [users' pattern 1 ] -----------------------------------------------------------
    (1) he enters "My name is"
    (2) he clicks the button "<b>".
    (3) he enters " John".
    (4) he clicks the button "</b>".
    (5) he enters the period ".".
    [ /users' pattern1] -----------------------------------------------------------

    So far so good.

    But users rather do modify than enter it correctly from the first like the following process.

    [users' pattern 2] -----------------------------------------------------------
    (1) he enters " My name is John."
    (2) he puts his mouse between "is" and "John".
    (3) he clicks the button "<b>".
    (4) he puts his mouse between "John" and the ".".
    (5) he clicks the button "</b>"
    [ /users' pattern 2 ] --------------------------------------------------------

    The above javascript has no problem in the [ users' pattern 1 ].
    But it has a problem if a user follow [users' patter 2] becuase when he puts his mouse between " is" and " John" or "John" and " .", and click the button "<b>" or "</b>" , the <b> or </b> tag is created at the end of his message.

    Expected result : "My name is <b> John</b>.
    Actual result : "My name is John.<b></b>

    How can I make the result as I expected when a user follows [users' pattern 2 ]?

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's an old version of a more complete script that I have (but not online now - my primary server is down).

    It still has the basic functionality you are after.

    http://beetle.kungfoohampster.com/taeditor.htm
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I have to say, I am afraid, The link you suggested is not helful.

    It has the problem as same as the code I posted.

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, I see. You want the first click to make the <b>, and the 2nd to make the </b>

    Sorry - this version of the script is too old. I'll see if I can upload the newest version
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    You want the first click to make the <b>
    No, I want the <b> should be created before "John".

    when a user put his mouse before "John" and click the button "<b>".

    The message should looks like the following

    "My name is <b> John."

    But the codes I posted and you suggested make it like the following.
    "My name is John. <b>".

    Think it, please, "the user is modifying his message."

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No - believe me, I understand. It's just that there is no other schema elsewhere that I've seen that operates the way you describe.

    Usually, instead of placing the cursor before the area intended for change, then clicking, then placing the cursor after the area intended for change, and clicking -- we are accustomed to selecting (highlighting) the area intended for change and clicking the button -- which the code I linked to allows.

    It's much more efficient (2 gestures vs. 4) and commonplace, as can be found in word processing software of all types.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  7. #7
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    believe me
    As I check your link in detail after believe you,
    I found it's much more convinient.

    Thank you

  8. #8
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    although the link you suggested works fine more than I expected, I found it's not easy to apply to my code.

    It's too complex to understand.
    I think it's beyond my stony brain.

    Futhermore,

    If uses "<body onload="init()">" which I don't like to use because the <body> part is included to many files in my site.
    The script doesn't need to every included page of my site.

    The script is needed to just two pages (form_page and update_pate)

    I don't know how to call the javacript without <body onload="init()"> .

    I think I need more simple code or other which doesn't use <body onloaed = something ( ) >.


    In short, I like to make the button "<b>" , in order to add <b> tag in front of "John" after entering "My name is John."(let's forget about </b> tag for a while for simplification)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •