SA Developer .NET

Welcome to SA Developer .NET Sign in | Join | Help
in Search

Problem using onchange to copy text.

Last post 07-31-2008, 11:30 by ProfK. 5 replies.
Sort Posts: Previous Next
  •  07-30-2008, 14:11 13779

    Problem using onchange to copy text.

    I want to mirror the contents of a textarea in a hidden input (represented here as another visible textarea for testing) using the onchange event of the first textarea. However, I cannot even get my event handler to execute, using the markup below. What am I doing wrong?

    head runat="server">
        <script type="text/javascript">
            function copyTextAreaToHiddenField(src){
                alert("Hello");               
                return null;
            }   
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="width: 300px; height: 150px; border-style: solid;">
            <textarea name="visibleText" onchange="copyTextAreaToHiddenField(this)" style="width:100%; height:100%;">
            </textarea>
        </div>
        <div style="width: 300px; height: 150px; border-style: solid;">
            <textarea id="hidden" name="hiddenText" style="width:100%; height:100%;">
            </textarea>
        </div>   
        </form>
    </body>

    Unscrambling Eggs: Decompiling ASP.NET
  •  07-30-2008, 15:14 13785 in reply to 13779

    Re: Problem using onchange to copy text.

    Rather try using the onkeypress or onkeydown event...

    "I would love to change the world, but they won't give me the source code"
    Meeting Place - chat online with anyone, anytime, no downloads or plugins required
  •  07-30-2008, 15:41 13786 in reply to 13785

    Re: Problem using onchange to copy text.

    I got onchange working; I think I had a problem with the function arguments.  FYI, this only didn't work in Firefox.

    Unscrambling Eggs: Decompiling ASP.NET
  •  07-30-2008, 16:04 13791 in reply to 13786

    Re: Problem using onchange to copy text.

    Hi Prof,

    I saw you got it working. Did you maybe try onPropertyChange() event? That has worked for me a lot in the past, and maybe it will help with FireFox too?

    Regards,


    The Question is the Answer, and the Answer is the Question!
  •  07-31-2008, 9:32 13794 in reply to 13791

    Re: Problem using onchange to copy text.

    function changeText() {

    document.form.hiddenthingy.value = this.value;

    }

    and

    onchange="BLOCKED SCRIPTchangeText();"

    ???

    I don't know if this will work, but I don't see why not. I don't understand the way you've done certain things in your script. i don't think there is a need for variable arguments in your function. although, i don't think you need a function either. i hope it helps...


    I'm going to regret forging this...
  •  07-31-2008, 11:30 13810 in reply to 13794

    Re: Problem using onchange to copy text.

    I need a function because the addition of this event takes place in a Javascript class derived from a 3rd party component, not directly in markup.  I chose a named function so that I could first get it working in plain markup, then just move to the actual customised control.

    Unscrambling Eggs: Decompiling ASP.NET
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems