# <render:encodeName> Tag

This tag lets you encode names such as HTML form names and JavaScript function names to make them unique such that the encoded names are unique within the context of the a portal page.

This tag frees you from dealing with potential name collisions that occur when two or more portlets (or multiple instances of the same portlet) use the same name to in the generated markup.

## Syntax

<tagName attribute="value">
</tagName>

## Attributes

name

Required (String) - The name to encode. The name can be read in as a variable. If the name is a valid Java identifier, the encoded name will also be a valid Java identifier.

var

Optional (String) - The variable that will contain the value of the URLencoded names.

scope

Optional (String) - This attribute has three primary variations:

PAGE SCOPE - (This is the default) The named reference remains available in this PageContext until the return from the current Servlet.service() invocation.
REQUEST SCOPE - The named reference remains available from the ServletRequest associated with the Servlet that until the current request is completed.

SESSION SCOPE - (Valid only if this page participates in a session). The named reference remains available from the HttpSession (if any) associated with the Servlet until the HttpSession is invalidated.

## Example

This example shows a JSP with an HTML form and a JavaScript function that populates value of a text field.

    <form action="…" method="POST">

       <input name="Name" id="nameField" value=""/>

    </form>

    <script type="text/javascript" language="JavaScript">
    function replaceIt()
    {
    var elem = document.getElementById("nameField");
    elem.value = "Some Value";
    }
    </script>

This JSP fragment may not function as expected when the value of the id attribute on the input field is not unique. This may happen, for example, when there is another portlet on the same page using the same value for the id attribute or the name of the JavaScript function. In order to avoid this, you must encode both the JavaScript function name and the value of the attribute as shown below:

    <form action="…" method="POST">

     <input name="Name" id="<render:encodeName name=”nameField”/> " value=""/>

    </form>

    <script type="text/javascript" language="JavaScript">
    function <render:encodeName name=”replaceIt”/>()
    {
    var elem = document.getElementById("nameField");
    elem.value = "Some Value";
    }
    </script>
    The use of this tag will now ensure that the id attribute and the function name are rewritten to be unique in the context of the generated HTML.