/    Sign up×
Community /Pin to ProfileBookmark

Type in text area using keys and a button

Hello,
I have a page with a text area and an image with the copy sign on it. When the copy sign image is pressed the copy sign will appear in the text box with the cursor right behind it.

I have a couple of problems.

  • 1.

    I would like to go back with the cursor in the text that is written and then enter a new copy sign if I want to at that specific location with the cursor right behind it. If I move the cursor back anywhere in the text and then press the copy button the sign now appears at the last position in the string.

  • 2.

    When the copy sign is pressed in the very beginning, I would like the text that is already entered in the text box initially (-Click here to enter text) to disappear and the copy sign to be the first sign to appear without having to start clicking in the text area. This is by far not as important as the problem mentioned in 1. However it would be nice to solve it as well.

  • You can see the page here:

    [url]http://www.trhtk.no/Lenker/vti_ex/tb/textbox.html[/url]

    It is also interesting why the text area moves up in IE when the copy sign is pressed so that the whole box is visible in the window in lower resolutions. Would be nice to know why that happens and how it can be controlled even though it is not so much of a problem.

    I hope someone can help me with this. I appreciate all the help I can get ?

    Here is the relevant code:

    <script language=”javascript” type=”text/javascript”>

    function get_focus() {

    document.getElementById(“inputtext”).focus();
    }

    function clearText(field) {

    if (field.defaultValue == field.value) field.value = ”;
    else if (field.value == ”) field.value = field.defaultValue;

    }

    if (document.images) {
    img_on =new Image(); img_on.src =”images/copy_down.gif”;
    img_off=new Image(); img_off.src=”images/copy_up.gif”;
    }

    function handlePress() {
    if (document.images) document.imgName.src=img_on.src;
    }

    function handleRelease() {
    if (document.images) document.imgName.src=img_off.src;
    }

    </script>

    <table width=960 bgcolor=”#f1ebc7″ border=”0″ cellspacing=”0″ cellpadding=”0″ class=brown>
    <tr>
    <td colspan=2 height=10></td>
    </tr>
    <tr>

    <form name=”myform”>

    <td width=19></td>
    <td><img name=imgName src=”images/copy_up.gif” OnMouseDown=”myform.inputtext.value=myform.inputtext.value + ‘&copy;’, handlePress();return true;” OnMouseUp=”document.myform.inputtext.focus(), handleRelease();return true;” onMouseOut=”handleRelease();return true;”></td>
    <td width=104></td>
    <td valign=middle>
    <input style=”width:100px;height:30px;font-size:11px;” type=”reset” value=”START AGAIN” id=reset1 name=reset1>
    </td>
    <td width=404></td>
    </tr>
    <tr>
    <td height=5 colspan=28></td>
    </tr>
    </table>

    <table width=960 bgcolor=”#f1ebc7″ border=”0″ cellspacing=”0″ class=brown>
    <tr>
    <td width=16></td>
    <td><textarea id=dummy name=”inputtext” value=”” onFocus=”clearText(this)” onBlur=”clearText(this)”>- Click here to enter your text

    </textarea>
    </td>
    <td width=14></td>

    </form>

    </tr>
    <tr>
    <td colspan=3 height=15></td>
    </tr>
    </table>

    to post a comment
    JavaScript

    1 Comments(s)

    ×

    Success!

    Help @pelcones spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.24,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...