Faster Javascript text replace

Posted by Stacey on Stack Overflow See other posts from Stack Overflow or by Stacey
Published on 2010-04-07T20:53:48Z Indexed on 2010/04/07 21:03 UTC
Read the original article Hit count: 162

Filed under:

Given the following javascript (jquery)

        $("#username").keyup(function () {
            selected.username = $("#username").val();

            var url = selected.protocol +
                (selected.prepend == true ? selected.username : selected.url) + "/" +
                (selected.prepend == true ? selected.url : selected.username);

            $("#identifier").val(url);
        });

This code basically reads a textbox (username), and when it is typed into, it reconstructs the url that is being displayed in another textbox (identifier).

This works fine - there are no problems with its functionality. However it feels 'slow' and 'sluggish'. Is there a cleaner/faster way to accomplish this task?

Here is the HTML as requested.

<fieldset class="identifier delta">
    <form action="/authenticate/openid" method="post" target="_top" >
        <input type="text" class="openid" id="identifier" name="identifier" readonly="readonly" />
        <input type='text' id='username' name='username' class="left" style='display: none;'/>
        <input type="submit" value="Login" style="height: 32px; padding-top: 1px; margin-right: 0px;" class="login right" />
    </form>
</fieldset>

The identifier textbox just has a value set based on the hyperlink anchor of a button.

© Stack Overflow or respective owner

Related posts about jQuery